I had a problem regarding how to evaluate if a is being animated and blocking a click operator based on this information. I could not use :animated as I was using a jQuery plugin for the animation which would break that attribute. Benjamin Powers answered my question by creating a custom attribute and evaluating that instead. ( http://jsfiddle.net/g5mJd/22/ )
However I have been playing around with the code, and I was curious if I could replicate the effect using a variable instead of an attribute. Here is my attempt: http://jsfiddle.net/g5mJd/24/
However it seems that this code does not permanently turn my variable false:
function() {
$("#block").transition({
x: '+=100'
}, 500, function() {
var anim = false;
console.log(anim)
})
In the console log it will state that the variable is false, but if I check it again, it become true. What am I doing wrong? (see the jsfiddle for the full code)
EDIT: So I right now this function turn var anim “false” but this instantly changes back to “true”, making a button unclickable (The button can only be clicked if anim is “false”)
The problem is the
varin the following line of code:That creates a local variable of the same name and sets it to
false, it doesn’t update the otheranim. Removevar:…and it will work as shown here: http://jsfiddle.net/g5mJd/25/
(Do not remove
varfrom the declaration ofanimat the top of the code in your fiddle.)