jQuery - toggled allowed animations.. nothing works -
nothing happens when click. if assign variable inside first if statement click works.. guess makou variable incorrect.
var makou = true; if(makou == true){ $( ".box_box" ).click(function() { $( ".box" ).animate({ top: "+=300", }, 50, function() { }); makou = false; }); } if(makou == false){ $( ".box_box" ).mouseleave(function() { $( ".box" ).animate({ top: "-=300", }, 50, function() { }); makou = true; }); }
true , false has written small letters @spokey said , second event mouseleave never set because variable makou true. , when click makou going false mouseleave not set again after click. put if condition inside mouseleave event handler this:
var makou = true; if (makou) { $( ".box_box" ).click(function() { $(this).unbind('click'); // unbind click allow 1 time $( ".box" ).animate({ top: "+=300", }, 50, function() { }); makou = false; }); } $( ".box_box" ).mouseleave(function() { if(!makou) { $( ".box" ).animate({ top: "-=300", }, 50, function() { }); makou = true; } here jsfiddle: http://jsfiddle.net/5dzt1v6f/5/
Comments
Post a Comment