Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery、window.scroll、定位横幅_Jquery - Fatal编程技术网

jquery、window.scroll、定位横幅

jquery、window.scroll、定位横幅,jquery,Jquery,我想在滚动时放置横幅: 代码是 $(window).scroll(function(){ offset = $(window).scrollTop()+80; var h = $(window).height(); if(offset < 80 && offset < (h-800)) { offset = 80; } $('#sidebar1').animate({top:offset}, 450)

我想在滚动时放置横幅:

代码是

$(window).scroll(function(){
    offset = $(window).scrollTop()+80;
    var h = $(window).height();

    if(offset < 80 && offset < (h-800))
    {
        offset = 80;
    }

    $('#sidebar1').animate({top:offset}, 450);
});
问题是偏移量是动态的,向下滚动时会发生变化,横幅超出窗口,向下滚动时会缓慢向上滑动。我想要一个不断的动画,同时上下滚动


是否有类似于“底部”而不是“顶部”的属性,或者是否存在除滚动以外的事件以实现持续滚动?

我知道这篇旧文章,但如果有人正在寻找解决方案,请参阅jQuery stop方法,代码写在下面

$(window).scroll(function(){
    offset = $(window).scrollTop()+80;
    var h = $(window).height();

    if(offset < 80 && offset < (h-800))
    {
        offset = 80;
    }
    $('#sidebar1').stop();
    $('#sidebar1').animate({top:offset}, 450);
});