I am trying to trigger an animation when the user scrolls down the page. So when he scrolls beyond a certain point, I want to have a div sliding in the webpage and I don't want it to slide away if the user scrolls up.
It works fine except that when I scroll up and down during the animation it delays it and the motion is not fluid at all.
I am using this javascript to trigger the animation:
$(document).ready(function() {
jQuery(function($) {
function fixDiv() {
var $cacheLaptop = $('#red-div');
var check=new Boolean();
check=false;
if ((check==false) && ($(window).scrollTop() > 500)) {
check=true;
$cacheLaptop.stop().animate(
{ left: 0 }, {
duration: 1000,
});
}
}
$(window).scroll(fixDiv);
fixDiv();
});
});
I have created a jsfiddle so you can see my problem: http://jsfiddle.net/B4WEV/3/
Does anyone have an idea how to fix this?
Many thanks!