Skip to content
Advertisement

How to control animate function on button click?

I have two divs named “arrow” and “inner”. I am trying to control the animate slide function when the div is clicked but have been unfortunate. The issue is noticeable when clicking very fast on the “arrow” div after user stops clicking the div is still sliding. I set the animate function under a small delay but I still experience lag. Here is my example code:

JavaScript

Advertisement

Answer

Just change your code

JavaScript

to

JavaScript

and

JavaScript

to

JavaScript

Please see following Link for example : http://jsfiddle.net/UAYTw/1/

you can also use $(“#inner”).stop(true, false).animate() instead of $(“#inner”).stop(true, true).animate(). as per your choice.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement