Css3 Keyframes Animation On Click (with Addclass). How To Restart Css3 Animation With Adding Css Class?
I have a problem. Im using Bounce.js to create nice menu animations (with some cool effects). Bounce.js using css keyframes animations which can be problematic to restart. I got me
Solution 1:
You can do it in a serval ways.
One way is to trigger re-flow of the element before adding animation class to it.
element.offsetWidth = element.offsetWidth;
For example (vanilla JS):
if (element2.classList.contains('show')) {
element2.classList.remove("show");
//restarting css3 keyframe animation
**element2.offsetWidth = element2.offsetWidth;**
element2.classList.add("hide");
}else{
element2.classList.remove("hide");
//restarting css3 keyframe animation
**element2.offsetWidth = element2.offsetWidth;**
element2.classList.add("show");
}
jQuery version:
if(settingPopup.hasClass('show')){
settingPopup.removeClass('show');
//line below is a fix to restart css3 keyframe animation//settingPopup.outerWidth(settingPopup.outerWidth)
settingPopup.outerWidth(settingPopup.outerWidth).addClass('hide');
}else{
settingPopup.removeClass('hide');
//line below is a fix to restart css3 keyframe animation//settingPopup.outerWidth(settingPopup.outerWidth)
settingPopup.outerWidth(settingPopup.outerWidth).addClass('show');
}
And here is working fiddle for it: https://jsfiddle.net/zpawpvke/2/
Post a Comment for "Css3 Keyframes Animation On Click (with Addclass). How To Restart Css3 Animation With Adding Css Class?"