3

我正在尝试使用 angular 指令实现水平 iScroll。

这是我的指令代码。

link: function(scope, elem, attrs) {
        scope.winWidth = window.innerWidth;
        scope.iScrollWidth = scope.winWidth *8.5 +'px';
        jQuery(angular.element(attrs.thelist)).css({'width':scope.iScrollWidth}); 

        var k_videoScroll = new iScroll(angular.element(attrs.scrollwrap),{
            snap: true,
            bounce: false,
            checkDOMChanges: false,
            momentum: false,
            hScrollbar: false,
            vScrollbar: false,
            overflow: false
        });

我的 html 页面中有一个 div 标记,其 id 与 attrs.scrollwrap 相关

<div id="videolist" class="videoScrollWrap" options="#thelist" wrapper="#deal-wrap"   scrollwrap="#videoReviewsWrap">    
   <div id="videoReviewsWrap">
      <ul id="thelist">
         <li id='deal-wrap' ng-repeat="video in videoList" videoList='video'></li>
      </ul>
    </div>
</div>

我遇到的问题是'无法设置未定义的属性'溢出''。

TypeError: Cannot set property 'overflow' of undefined
at Object.iScroll (http://localhost/swordfish/web/js/lib/iscroll.js:89:31)
at setScroll (http://localhost/swordfish/web/js/directives/d-product-details.js:395:33)
at link (http://localhost/swordfish/web/js/directives/d-product-details.js:405:13)
at o (http://localhost/swordfish/web/js/lib/angular/angular.min.js:42:187)
at e (http://localhost/swordfish/web/js/lib/angular/angular.min.js:38:28)
at http://localhost/swordfish/web/js/lib/angular/angular.min.js:37:118
at <error: illegal access>
at Object.e.$broadcast (http://localhost/swordfish/web/js/lib/angular/angular.min.js:88:517)
at http://localhost/swordfish/web/js/lib/angular/angular.min.js:81:85
at i (http://localhost/swordfish/web/js/lib/angular/angular.min.js:76:207) <div id="videolist" class="videoScrollWrap ng-isolate-scope ng-scope" options="#thelist" wrapper="#deal-wrap" scrollwrap="#videoReviewsWrap"> angular.min.js:60

(匿名函数)

可能是什么问题?似乎定义新 iScroll 的语法不正确。这样做的正确方法是什么?

提前致谢!

4

1 回答 1

1

我弄清楚了这个问题。这是因为当我尝试获取 (attrs.scrollwrap) 它实际上是在重新调整对象。但是 iScroll 库试图直接获取对象的子元素,并设置该对象的样式属性。一旦我尝试使用 (attrs.scrollwrap[0]) 访问 div 元素,问题就解决了。

于 2013-04-29T14:41:13.730 回答