jquery - How to detect if an element has scrolled out, but only once? -


i trying detect if element has been scrolled out , have done 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 anchor in body text, hoping clone , make fixed nav out of once div.intro scrolled out.

my problem code fires element out of view, keeps firing. cannot more more keep firing.

is there way fire 'out' once it's out , 'in' once it's in? aside setting variable.

to execute event once can do

$(window).one('scroll', function(){     var $btn = $('#intro div.summary a[href=#top]');     if($(window).scrolltop() > ($btn.offset().top+$btn.height())) {         console.log('out');     } }); 

Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

java - Getting corefrences with Standard corenlp package -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -