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:
- container dynamic, height varies based on height of images received.
- 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
Comments
Post a Comment