iScroll-属性未定义错误



我试图在一个页面上添加两个iScroll实例,但我不认为这是原因:

function loaded() {
    $('.iScrolls').each(function(){
        var $this = $(this);
        var $id = $this.attr('id');
        if( $id ) {
            $scrollers[$id] = new iScroll( $id, {
                snap: true,
                momentum: false,
                hScrollbar: false,
                onScrollEnd: function () {
                    $('#indicator > li.active').removeAttr('class');
                    $('#indicator > li:nth-child(' + ( this.currPageX + 1) + ')').removeAttr('class').addClass('active');
                }                              
            });
            $('.prev', $this).click(function(){
                $scrollers[$id].scrollToPage('prev', 0);
                return false;            
            });
            $('.next', $this).click(function(){
                $scrollers[$id].scrollToPage('next', 0);
                return false;                
            });
        }
    });
}
document.addEventListener('DOMContentLoaded', loaded, false);

当"滚动到页面"被触发时,我得到错误:

Uncaught TypeError: Cannot read property 'length' of undefined

iScroll.scrollTo iScroll.js:984

iScroll._end iScroll.js:614

iScroll.handleEvent

我的问题是,以前有人遇到过这种情况,知道是什么原因造成的吗?

关于

试图在隐藏容器内初始化。。。这是不…干杯!

刚刚遇到这个问题。最后是一个愚蠢的错误,因为我传递的是jQuery样式的"#wrapperID",而不仅仅是元素id的"wrapperID"

希望这能帮助到别人。

iScrolls是您的div类名。你能在这个div上创建一个id吗?

示例:

<div class="iScrolls" id="iScrolls">
    <div id="main">
        <div id="thelist">
                // Body part
        </div>
     </div>
</div>

最新更新