【问题标题】:Uncaught TypeError: Cannot use 'in' operator to search for 'scrollLeft' in undefined未捕获的类型错误:无法使用“in”运算符在未定义中搜索“scrollLeft”
【发布时间】:2013-06-15 14:26:48
【问题描述】:

根据jQuery API Documentation 和此处找到的一些示例,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);
});

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

【问题讨论】:

    标签: javascript jquery jquery-animate


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢。正如我所说,这一定是我忽略的一些简单而愚蠢的事情。谢谢。
    猜你喜欢
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2014-07-15
    • 2020-11-14
    • 2013-09-01
    • 1970-01-01
    相关资源
    最近更新 更多