Skip to content

Instantly share code, notes, and snippets.

@qassa
Last active November 4, 2015 09:46
Show Gist options
  • Save qassa/98a152eb0dee465047fd to your computer and use it in GitHub Desktop.
Save qassa/98a152eb0dee465047fd to your computer and use it in GitHub Desktop.
Анимация плавно выезжающего элемента страницы с заданным значением таймера
var element = document.getElementById("im");
var currentPosition = element.offsetTop; //Получаем текущее положение блока, который будет выплывать
smoothAnimation = requestAnimationFrame(function anim(time) {
currentPosition++;
element.style.top = currentPosition +"px";
smoothAnimation = requestAnimationFrame(anim); // The animation would not stop after 1.5 sec if delete smoothAnimation in this line because the fucntion reference changes every time it's called
});
setTimeout(function(){
cancelAnimationFrame(smoothAnimation);
},1500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment