简体   繁体   中英

How to change class when it scroll to end of div?

Ok i have 3 divs. I have fixed menu in second div and i want that fixed menu is only fixed in that second menu and when it come out of that div it is display:none; This is my fiddle. Any suggestion?

https://jsfiddle.net/wx38rz5L/1817/

if ($(this).scrollTop()>=$('.compare-wrapper').position().top)
    $('.compare-menu-fixed').css('display','block');
else
    $('.compare-menu-fixed').css('display','block');

Put it inside scroll event:

$(document).on( 'scroll', function(){
    if($(this).scrollTop()>=$('.compare-wrapper').position().top)
        $('.compare-menu-fixed').css('display','block');
    else
         $('.compare-menu-fixed').css('display','none');
});  

Check Demo Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM