;Jquery:将页面从当前屏幕位置向下移动 100 像素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4883105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:06:48  来源:igfitidea点击:

;Jquery: animate page down 100px from current screen position

jqueryscrolltop

提问by android.nick

I need to animate a scroll from the current screen position, down a set number of pixels.

我需要从当前屏幕位置开始动画滚动,向下移动一定数量的像素。

    $('html,body').animate({
        scrollTop: $(window).position().top += 100
    });

or?

或者?

    $('html,body').animate({
        scrollTop: '+=100px'
    });

回答by David Tang

Just change:

只是改变:

scrollTop: $('body').position().top += 100

To this:

对此:

scrollTop: $(window).scrollTop() + 100

See demo: http://jsfiddle.net/fpxuC/

见演示:http: //jsfiddle.net/fpxuC/

回答by ajma

Check out the jQuery.ScrollTo plugin. You can do something like: $(...).scrollTo( '+=100px', 800 );

查看 jQuery.ScrollTo 插件。您可以执行以下操作:$(...).scrollTo( '+=100px', 800 );

Check out the sample for everything this plugin can do: http://demos.flesler.com/jquery/scrollTo/

查看此插件可以执行的所有操作的示例:http: //demos.flesler.com/jquery/scrollTo/

回答by Gaurang

$('html,body').animate({
        scrollTop: $(window).position().top += 100
    })

$('html,body').animate({
        scrollTop: '+=100px'
    })

scrollTop: $('body').position().top += 100

scrollTop: $(window).scrollTop() + 100