Ionic转盘调整$http调用的大小问题
Ionic carousel resize issue with $http call
我正在Ionic中使用一个插件来创建一个旋转木马(https://github.com/ksachdeva/angular-swiper)它有一个简单重复的演示。我使用$http将repeat替换为我自己的repeat,这造成了一个问题,因为加载图像的延迟会导致滑块在调整大小之前断裂。HTML看起来像这样:
<ks-swiper-container autoplay="500" initial-slide="1" speed="5000" loop="false" show-nav-buttons="false" slides-per-view="2" space-between="20" pagination-clickable="false" override-parameters="{effect: 'coverflow',coverflow: {rotate: 0,stretch: 0,depth: 100,modifier: 1,centeredSlides: true,slideShadows : false}}" on-ready="onReadySwiper(swiper)">
<ks-swiper-slide class="swiper-slide" ng-repeat="feature in featured track by feature.id">
<img imageonload="" ng-src="{{feature.thumbnail_images.thumbnail.url}}" width="100%">
<h6 ng-bind-html="feature.title"></h6>
</ks-swiper-slide>
<ks-swiper-slide class="swiper-slide">
<img src="img/more.png" style="transform: rotate(180deg);" width="100%">
<h6>Read More</h6>
</ks-swiper-slide>
</ks-swiper-container>
我把我工厂的图像称为:
.controller('SwipeCtrl', function($scope, Featured) {
$scope.swiper = {};
$scope.onReadySwiper = function (swiper) {
swiper.on('slideChangeStart', function () {
});
swiper.on('onSlideChangeEnd', function () {
});
};
$scope.featured = [];
Featured.all().then(function (response,swiper){
$scope.featured = response;
for (var i =0; i < $scope.featured.length; i++) {
$scope.featured[i].date = new Date($scope.featured[i].date);
}
},
function (err) {
if(window.localStorage.getItem("featured") !== undefined) {
}
}
);
})
我试过添加一个$timeout,但没有帮助。我找到了一个创建指令的建议:
.directive('imageonload', function ($rootScope, $timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('load', function() {
$timeout(function(){
$rootScope.swiper.updateSlidesSize();
});
});
}
};
});
但我不断得到"updateSlidesSize()未定义"。
真的不太确定如何解决这个问题。。。
我遇到了同样的问题。我首先注意到的一件事是,我的swiper.js版本(而不是angular swipper.js)没有updateSlidesSize()函数。所以我找到了一个新版本的swipper.js,它包含了这个功能。
因此,这应该照顾到未定义的。现在,把所有这些放在一起,我做了什么:
//My HTML
<ks-swiper-container initial-slide="1" loop="false" show-nav-buttons="false" slides-per-view="3" space-between="5" pagination-clickable="false" on-ready="onReadySwiper(swiper)">...</ks-swiper-container>
//My controller
$scope.swiper = {}; //initialize
$scope.onReadySwiper = function (swiper)
{
$scope.swiper = swiper; //update when the swiper is ready
};
$scope.myData=[1,2,3,4,5];
$http.jsonp(myurl+'&callback=JSON_CALLBACK').success(function(data)
{
$scope.myData=data; //e.g.: [6,7,8]
$timeout(function() //give the data a moment to propagate
{
$scope.swiper.updateSlidesSize(); //now run the sizing update - can also use just .update()
$scope.swiper.slideTo(0); //show the slider from the beginning
}, 300);
});
我只在谷歌Chrome中进行了模拟测试,而不是在实际的移动设备上。
相关文章:
- d3-js快速事件调用问题
- 运行Infinite Scroll后调用函数时出现问题
- "访问控制允许起源”;通过javascript从http页面调用同一网站的httpsurl时出现问题
- Meteor HTTP调用出现问题
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 使用setInterval调用原型函数时出现问题
- 在HTML中调用函数时出现问题
- 在javascript中调用自定义谷歌搜索标签时出现问题
- setTimeout调用自身的任何问题
- Node.js-异步方法调用问题
- 客户端和服务器端调用 asp 按钮的问题
- 递归承诺调用 - 内存范围变量问题
- 在单击按钮时调用 jquery 函数时出现问题
- JS onclick问题调用css精灵的图片
- 节点/快速路由问题-调用不正确的路径
- 数据源查询回调问题(调用顺序,改变全局变量的能力)
- 更新面板中的中继器- itemcommand代码问题-调用javascript函数与ScriptManager在代码后面
- android:从java问题调用javascript
- 同源策略问题调用sharepoint web服务
- 从 Java 脚本安全问题调用已签名的 Java 小程序