const status = [
"left:0px;",
"left:10px;",
"left:20px;",
"left:30px;",
"left:40px;",
];
const list = $("#carousel > ul > li");
const len = list.length;
let pointer = 0;
function change(dir) {
pointer = outRange(dir ? ++pointer : --pointer);
for (let i = 0, len = status.length; i < len; i++)
$(list[outRange(pointer + i)]).attr("style", status[i]);
}
function outRange(val) {
return val >= len ? 0 : val < 0 ? len - 1 : val;
}
$("#bu1").click(function () {
change(true);
});
$("#bu2").click(function () {
change(false);
});
```
标签:jQuery,function,const,轮播,val,len,滑动,pointer,left
From: https://www.cnblogs.com/laremehpe/p/17363654.html