I am trying to detect if an element has been scrolled and made the following code
$(window).bind('scroll', function(){
var $btn = $('#intro div.summary a[href=#top]');
if($(window).scrollTop() > ($btn.offset().top+$btn.height())){
console.log('out');
}
});
I have an anchor in some body text that I hope to clone and make fixed navigation after div.intro scrolls.
My problem is that the code fires as soon as the element leaves the field of view, but continues to shoot. Therefore, I canβt do it anymore, as it will shoot more and more.
Is there any way to shoot βoutβ after it comes out and βinβ after turning it on? Besides just setting a variable.
source
share