I was playing with animate.css and built my own Javascript function to trigger animation events.
This very simple function (triggered through an onClick event on a button) is only three (four) lines long, but it runs into a truly mind-boggling error.
The anim
function first removes the class from the element, then adds it, so that multiple presses on the button will keep running the animation. Unfortunately, I found that it didn't work! That is, the animation runs once (the first time only), and then fails to run subsequently.
In a stroke of serendipity, I discovered that adding the line console.log(element_name)
in line 3
suddenly made it work.
I was very puzzled with this behaviour, and so I experimented with adding other console.log
lines but strangely only the line console.log(element_name)
works!
To ensure that it wasn't a quirk in the development environment, I reproduced it in JSFiddle here.
function anim(element_name){ //'animate' is a reserved keyword
removeClass(element_name, 'bounceInDown');
console.log(element_name); //Very cute behaviour!!! when I put this line here, it works, if i don't it doesnt.
//console.log('a'); //Not all console.logs work
addClass(element_name, 'bounceInDown');
}
function addClass(element, classname){
element.classList.add(classname);
}
function removeClass(element, classname){
element.classList.remove(classname);
}