javascript - Trigger events when pageYoffset >= div.offsetTop -


i working on simple navigation site uses window.pageyoffset change label on navigation button fixed document right, , secondly, click actions on button scrolls top position of respective container based on label.

note:

  1. container dynamic, height varies based on height of images received.
  2. container b has fixed height, i've not decided on height going functionality going i've considering 700px.

how calculate pageyoffset, such label change triggered when pageyoffset >= containerb.offset.top? i'm not sure if condition met or chasing wild goose. there better way tackle problem.

current solution

this current solution label change triggers when scrollbar not close topposition of containerb. i've attached image depicts page.

window.addeventlistener( "optimizedscroll", function optimizedscrollfunc( ) {     var self = voapp,         gototop = document.getelementbyid( "cc-gototop-js" ),         winpageyoffset = window.pageyoffset,         windowinnerheight = window.innerheight,         documentscrollheight = document.body.scrollheight,         topstoriesloadmore = document.getelementbyid( "cc-tsloadmorewrapper-js" );         dom.glanceuidiv = document.getelementbyid( "cc-glancewrapper-js" ).offsettop;      console.log((winpageyoffset + windowinnerheight), documentscrollheight);      if ( winpageyoffset + windowinnerheight >= documentscrollheight ) {         console.log("fired");         $( gototop )             .removeclass( "cc-thisweek" )             .addclass( "cc-today" );         $( topstoriesloadmore )             .removeclass( "cc-tsloadmorewrappervisible" );     }     if ( winpageyoffset < 200 ) {         $( gototop )             .removeclass( "cc-today" )             .addclass( "cc-thisweek" );     } } ); apputil.f_throttle( "scroll", "optimizedscroll" ); 

page wireframe

enter image description here


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -