вопрос о анимации
Есть анимация , как сделать так чтоб анимация не вызывалась второй раз пока не окончить роботу первый setInterval ?
function animate (opts) { var start, move; start = new Date(); move = setInterval(function () { var progres = (new Date - start) / opts.progres; if(progres >= 1) progres = 1; opts.init(progres); /* для каждого свою дыстанцию */ if(progres == 1) clearInterval(move); },10) } function draw (to, progres, elem) { animate({ to: to, progres: progres, init: function (progres) { elem.style.left = this.to*progres + 'px'; } }) } |
Например, через глобальную переменную.
|
или замыкание другой функцией, или объект в котором animate - метод
|
не проверял но должен работать
function animate (opts) { var start, move; if( animate.state ) return; animate.state = true; start = new Date(); move = setInterval(function () { var progres = (new Date - start) / opts.progres; if(progres >= 1) progres = 1; opts.init(progres); /* для каждого свою дыстанцию */ if(progres == 1) { animate.state = false; clearInterval(move); } },10) } function draw (to, progres, elem) { animate({ to: to, progres: progres, init: function (progres) { elem.style.left = this.to*progres + 'px'; } }) } |
Часовой пояс GMT +3, время: 23:04. |