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

不羁的心 提交于 2019-11-27 02:03:54

问题


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'
    });

回答1:


Just change:

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

To this:

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

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




回答2:


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

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




回答3:


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

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

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

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


来源:https://stackoverflow.com/questions/4883105/jquery-animate-page-down-100px-from-current-screen-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!