1.這幾天一直在研究這個小插件的做法,如圖
2.開始想用angular來實現,發現去綁定滑動事件進行判斷滑動距離很麻煩,考慮到之前用過swiper這個插件,就嘗試用swiper做了一下,很快就成功了。
3.貼出代碼來看看吧:
html部分,我用的指令來做的,所以html部分很少啦:
<ion-content class="padding">
<list-scroll data="list"></list-scroll>
<!-- Swiper -->
</ion-content>
js部分:
angular.module('starter.controllers', [])
.directive('listScroll',function(){
return {
restrict:'E',
scope:{
data:'='
},
template:'<div class="chooseDiv">'+
'<div class="swiper-container">'+
'<div class="swiper-wrapper">'+
'<div class="swiper-slide" ng-repeat="x in data" repeat-finish="renderFinish()">{{x}}</div>'+
'</div>'+
'</div>'+
'<div class="mark_div"></div>'+
'</div>',
link:function($scope,element,attrs){
$scope.renderFinish = function(){
var mySwiper1 = new Swiper('.swiper-container',{
direction: 'vertical',
slidesPerView: 5,
centeredSlides: true
})
}
}
}
})
.directive('repeatFinish',function(){
return {
link: function(scope,element,attr){
if(scope.$last == true){
console.log('ng-repeat執行完畢')
scope.$eval( attr.repeatFinish )
}
}
}
})
.controller('DashCtrl', function($scope,$ionicScrollDelegate) {
console.log($scope);
$scope.list = ['please choose','湖北','湖南','浙江','江蘇','廣東','廣西','深圳','福建'];
})
這就是所有代碼了,,終於實現了,兩天的努力沒白費!
注:swiper的配置請參考[http://www.swiper.com.cn/api/Effects/2015/0308/194.html]