如图,怎么让i共享呢,现在是每次执行i都为0.
目前你在init 里面定义的i是个局部变量,外部访问不到,可否将它定义为vipdata 的一个属性,这样对于其他几个函数就是公开的了,不知道对不对,没有测试
给vipData对象新增一个属性来存储当前序列
var vipData = {
index: 0,
prev: function(){ this.index-- },
next: function(){ this.index++ },
init: function(){
var self = this
body.bind('swipUp', function() {
self.nextPage()
});
body.bind('swipDown', function() {
self.prevPage()
});
}
}
大概就是这个样子,还没有验证
var vipData = (function() {
var _i,
len,
pageList;
function prev(i) {
if(i == 0) {
return false;
}
console.log(i);
pageList.eq(1).show.siblings().show();
_i--;
}
function next(i) {
if( i == len -1) {
return false;
}
console.log(i);
pageList.eq(i).show().siblings().show();
_i++;
}
function init() {
var self = this,
_i = 0;
body.bind('swipUp', function() {
self.nextPage(_i);
});
body.bind('swipDown', function() {
self.prevPage(_i);
});
}
init();
return {
prevPage : prev,
nextpage: next,
init: init
}
})();