I'm trying to create an animation for a div after the scroll is larger than a value (in my case, 1100).
It works to a certain extent, but after it reaches 1100, every time it moves on the scroll, this effect runs again.
Here's my code:
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j(window).bind('scroll', function(){
if($j(this).scrollTop() > 1100)
$j('.testing')
.css("position","fixed")
.css("top","10px")
.animate({marginTop: '30px'}, 500)
.animate({marginTop: '10px'}, 500);
else
$j('.testing')
.css("position","relative")
.css("top","0")
.animate({marginTop: '0px'}, 500);
});
});
</script>
.testing is my div and whenever the scroll passes 1100 it runs almost infinitely.
My intention is that when it reaches 1100, it runs the animation and at the end of it, stay static with the position fixed until the scroll is less than 1100.