gpt4 book ai didi

angularjs - angularjs 指令中的 iScroll

转载 作者:行者123 更新时间:2023-12-04 07:46:36 25 4
gpt4 key购买 nike

我正在尝试使用 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 的语法不正确。正确的做法是什么?

提前致谢!

最佳答案

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

关于angularjs - angularjs 指令中的 iScroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16202028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com