Jquery Scrolling div - Prevent from entering site footer

前端 未结 1 1748
无人及你
无人及你 2021-01-14 17:48

I have a side menu on my site that i would like always visible.
To accomplish this, I am using the following code sample from this page:

http://camwebdesign.com/

1条回答
  •  隐瞒了意图╮
    2021-01-14 17:57

    Demo

    http://jsfiddle.net/NsfwM/

    fullscreen http://jsfiddle.net/NsfwM/embedded/result/

    JS

    var $scrollingDiv = $("#scrollingDiv");
    
    $(window).scroll(function(){            
        var y = $(this).scrollTop(),
            maxY = $('#footer').offset().top,
            scrollHeight = $scrollingDiv.height();
    
        if(y< maxY-scrollHeight ){
            $scrollingDiv
            .stop()
            .animate({"marginTop": ($(window).scrollTop()) + "px"}, "slow" );        
        }    
    });
    

    And another with your 30px offset in place http://jsfiddle.net/NsfwM/1/

    0 讨论(0)
提交回复
热议问题