10

根据jQuery API 文档和此处找到的一些示例,scrollLeft 是animate(). 但是,我不断收到此错误Uncaught TypeError: Cannot use 'in' operator to search for 'scrollLeft' in undefined

$('#prev a, #next a').click(function() {
    $(window).animate({scrollLeft: 500}, 1000);
});

我忽略了一些简单而愚蠢的事情吗?我究竟做错了什么?谢谢 :)

4

1 回答 1

19

窗口没有滚动条,它属于 body 或 documentElement(html 标签):

$('#prev a, #next a').click(function() {
    $('body, html').animate({scrollLeft: 500}, 1000);
});

看起来很奇怪,您可以使用 获得 windows scrollLeft 属性css(),但是在制作动画时,您会为 body 和 html 标签制作动画。

于 2013-06-19T06:56:04.083 回答