jquery - Maths for finding out when the bottom of the window is at an element -


so trying create event when element @ bottom of window. of course window sizes anything, struggling here on how work out.

my current code goes this, doesnt take account window size:

$(window).scroll(function(){     win_height = $(window).height();     scroll = $(window).scrolltop();     pos = $('#home_process').offset().top;     height = $('#home_intro_bg').height();     //$('#header_logo').html(win_height+' '+scroll+' '+pos+' '+height);     if(scroll > win_height-height) {         $('#home_process_steps li').fadein();     } }); 

i want code says this:

if #home_process becomes viewable within window - action.

how can work out?

please try this

$(window).scroll(function(){     var $elem = $("#home_process");     var $window = $(window);      var docviewtop = $window.scrolltop();     var docviewbottom = docviewtop + $window.height();      var elemtop = $elem.offset().top;     var elembottom = elemtop + $elem.height();      if((elembottom <= docviewbottom) && (elemtop >= docviewtop)){         alert(11)     } }); 

demo


Comments