0

我正在尝试在一页上添加 2 个 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);

当触发“scrollToPage”时,出现错误:

Uncaught TypeError: Cannot read property 'length' of undefined

iScroll.scrollTo iScroll.js:984

iScroll._end iScroll.js:614

iScroll.handleEvent

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

问候

4

3 回答 3

1

试图在一个隐藏的容器中初始化……那是不行……干杯!

于 2012-09-07T08:04:56.357 回答
0

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

例子:

<div class="iScrolls" id="iScrolls">
    <div id="main">
        <div id="thelist">
                // Body part
        </div>
     </div>
</div>
于 2017-02-23T08:45:29.113 回答
0

刚碰到这个。最终成为一个愚蠢的错误,因为我传递了 jQuery 样式“#wrapperID”,而不仅仅是元素 id“wrapperID”

希望对某人有所帮助。

于 2017-02-09T07:21:47.303 回答