jQuery scrollTo不起作用

5

我只是想在浏览器窗口中滚动到特定的DOM元素或绝对位置,但是却没有效果。这是我的代码:

$(window)._scrollable();
$('#scene_01_down').click(function(){
    $(window).scrollTo(2000,1000);
});

这里是该插件的文档:

http://flesler.blogspot.com/2007/10/jqueryscrollto.html

1个回答

22

你真的需要那个插件吗?

$("html,body").animate({
    scrollTop: 2000,
    scrollLeft: 1000
});

要滚动到特定元素:

var offset = $("#someElement").offset();
$("html,body").animate({
    scrollTop: offset.top,
    scrollLeft: offset.left
});

演示。


抱歉,我的意思不是要重复你的 - 而且,我更喜欢你的版本 :) - Zachary Kniebel
我讨厌人们不回答问题。但是这个做得很好,而且我一直讨厌那个插件 :) - Kevin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接