2012-09-07 34 views
0

我想补充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); 

当“scrollToPage被触发我得到的错误:

Uncaught TypeError: Cannot read property 'length' of undefined

iScroll.scrollTo iScroll.js:984

iScroll._end iScroll.js:614

iScroll.handleEvent

我的问题的存在有没有人碰到这个来知道是什么原因造成的?

关于

回答

1

正试图在一个隐藏的容器内初始化...这是一个不......没有......干杯!

0

刚才碰到了这个。结束了一个愚蠢的错误,因为我通过jQuery风格“#wrapperID”,而不是仅仅元素ID“wrapperID”

希望可以帮助别人。

0

.iScrolls是你的div类名。你可以在该div上创建一个ID吗?

实施例:

<div class="iScrolls" id="iScrolls"> 
    <div id="main"> 
     <div id="thelist"> 
       // Body part 
     </div> 
    </div> 
</div> 
相关问题