```DigsurGallery = {};
DigsurGallery.Rolling = function() {
this.change = null;
this.length = 0;
this.Arr = [];
this.alength;
}
// 对象下的一个方法
DigsurGallery.Rolling.prototype.FadeInOut = function(name, HasPaging, array, Barray) {
// 定义一个对象,这个对象对应着DigsurGallery.Rolling
var _this = this;
// 获取 盒子的名字
var oDiv = $('#' + name);
// 遍历数组,创建ul与li,并且赋给Id
for(var i = 0; i < array.length; i++) {
var oUlPageOne = $("
for(var l = 0; l < array[i].length; l++) {
var oli = $("");
oUlPageOne.append(oli);
var oImg = $("")
$(oImg).attr('src', array[i][l]);
oli.append(oImg);
}
oDiv.append(oUlPageOne);
$(oUlPageOne).attr('id', 'test' + i);
}
// 设置样式
oDiv.find('ul').css({
"display": "none",
"position": "relative",
"width": "100%",
"height": "100%",
"height": "100%",
});
// 判断 是否有点击事件
if(HasPaging == true) {
// 遍历添加当前的length为 0
for(var k = 0; k <= Barray.length; k++) {
_this.alength = 0;
_this.Arr.push(_this.alength);
}
// 做点击事件
for(var b = 0; b < Barray.length; b++) {
(function(arg) {
// 为按钮做点击函数
$("#" + Barray[arg]).click(function() {
$("#" + name + " ul").css("display", "none");
$("#" + "test" + arg).css("display", "block");
$("#" + "test" + arg + " li").eq(0).css("display", "block");
clearInterval(_this.change);
Testmove("test" + arg, arg, _this.Arr[arg]);
})
})(b)
}
}
// 让第一个ul 显示出来
$("#" + name + " ul:first").css("display", "block");
// 寻找ul
var lis = oDiv.find('li');
// 寻找img
var Lisimgs = lis.find('img');
// 给图片设置样式
Lisimgs.css({
"width": "100%",
"height": "100%",
"border-radius": "5px",
"box-shadow": "-3px 4px 7px #211f1f",
})
// 给li设置样式
lis.css({
"display": "none",
"width": "100%",
"height": "100%",
"position": "absolute",
"float": "left",
});
$("#test0 li").eq(0).css("display", "block");
// 定时器轮播
function Testmove(id, length, arlength) {
_this.change = setInterval(function() {
arlength++;
console.log("当前length为:" + arlength);
// 判断 个数
if(arlength == array[length].length) {
arlength = 0;
}
showaa(arlength, id);
console.log("当前id为:" + id);
}, 2000);
}
Testmove('test0', 0, this.length);
function showaa(length, id) {
$("#" + id + " li").eq(length - 1).fadeOut(1000); //将上一张图片隐藏
$("#" + id + " li").eq(length).fadeIn(2000); //将这张图片出现
}
}
代码在上面,每次点击的时候,都是从0开始运动,我需要的是,切换页面的时候,length会记录的。求大神