javascript - Ionic carousel resize issue with $http call -
i using plugin in ionic create carousel (https://github.com/ksachdeva/angular-swiper) has demo simple repeat. replaced repeat own using $http , has created problem in delay loading images causes slider break until resized. html looks this:
<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 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> i calling images factory this:
.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; (var =0; < $scope.featured.length; i++) { $scope.featured[i].date = new date($scope.featured[i].date); } }, function (err) { if(window.localstorage.getitem("featured") !== undefined) { } } ); }) i have tried adding $timeout did not help. found suggestion create directive:
.directive('imageonload', function ($rootscope, $timeout) { return { restrict: 'a', link: function(scope, element, attrs) { element.bind('load', function() { $timeout(function(){ $rootscope.swiper.updateslidessize(); }); }); } }; }); but keep getting "updateslidessize() undefined".
really not sure how fix this...
i had same issue. 1 of first things noticed version of swiper.js (not angular-swiper.js) did not have function updateslidessize(). found newer version of swiper.js , has function included.
so should take care of undefined. now, bringing together, here's did:
//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 swiper 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 data moment propagate { $scope.swiper.updateslidessize(); //now run sizing update - can use .update() $scope.swiper.slideto(0); //show slider beginning }, 300); }); i have tested in google chrome emulation - not on actual mobile device.
Comments
Post a Comment