Div不会停止使用Page滚动

Div wont stop scrolling with Page

本文关键字:Page 滚动 Div      更新时间:2023-09-26

在以下位置使用我的代码:http://jsfiddle.net/Pd7nm/

我希望侧边栏在某个时刻停止滚动页面,但它只是继续。我尝试了很多方法,但都不起作用。

这是Javascript方法的

 var windw = this;
$.fn.followTo = function ( pos ) {
var $this = this,
    $window = $(windw);
$window.scroll(function(e){
    if ($window.scrollTop() > pos) {
        $this.css({
            position: 'absolute',
            top: pos
        });
    } else {
        $this.css({
            position: 'fixed',
            top: 0
        });
    }
});
};
$('#side').followTo(250);

更新的JQuery Fiddle在这里

$(window).scroll(function() {
    var height = $(window).scrollTop();
    if(height>250){
        $(".sidebar").css({"position":"fixed","top":0});
    }
});

请参阅我在"br"标签中删除的演示

Demos - jsfiddle.net/Nu3eu/1/