jake jake - 1 year ago 81
CSS Question

Make the side div follow after certain scroll

Right now the div on the right follows the scroll all the time. If I want it to start following the scroll when the page is scrolled to the top of the div, and make it remain there when scrolled up, what more do I need to do?


var scrollTop = $(window).scrollTop();
$('.mSidebar').css( "top", scrollTop + 400 );

Answer Source

Use like this :



        if($(document).scrollTop() > 400) {
            var newPos = $(document).scrollTop() + 400 ;
            $('.mSidebar').css( {top:newPos});

        else {
            $('.mSidebar').css( {top:400});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download