A
A
Alexey2014-03-16 19:16:22
JavaScript
Alexey, 2014-03-16 19:16:22

How to stop Javascript/jquery animation?

Help me to understand! There are two buttons: one reduces the size of the block, the second increases it. But if you press any of the keys many times, the object will get smaller and smaller. Also with the second. It is necessary that the buttons increase and decrease the object only once and stop, but it turns out that it decreases and increases indefinitely (how many times you press it).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuri Lobanov, 2014-03-16
@iiil

Why don't you use toogleClass, for example?
upd: jsfiddle.net/iiil/e6wFz/1
Write whatever you want to the classes.

R
Roman Yakushev, 2014-03-23
@CanVas

$(document).ready(function() {
var anim = false;
        $(".news").click(function event() {
if (anim==false) { //если анимация не идёт, то анимируем
anim=true;      
$(".table").animate({
                  "margin-right": "+=60px",    
                  "height": "+=40px",
                  "width": "+=100px",
                }, 1000, function () { //функция которая выполнится по окончанию анимации
anim= false;
});
          });
} 

      });

V
Valery Demidov, 2014-03-16
@Fraideron

Put something like a flag in the code that will be responsible for the last action, and if it matches the previous one, it will not be executed ... The task would be simplified many times if you look at your code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question