$(function() {
//banner
var $banner = $(".hm_banner");
var width = $banner.width();
// 图片盒子
var imageBox = $banner.find("ul:eq(0)");
// 点盒子
var pointBox = $banner.find("ul:eq(1)");
// 所有的点
var points = pointBox.find("li");
var animateFuc = function() {
imageBox.animate(
{ transform: "translateX(" + -index * width + "px)" },
200,
"ease",
function() {
if (index >= 9) {
index = 1;
// 瞬间定位
imageBox.css({
transform: "translateX(" + -index * width + "px)"
});
} else if (index <= 0) {
index = 8;
imageBox.css({
transform: "translateX(" + -index * width + "px)"
});
}
// 点盒子 对应
points
.removeClass("now")
.eq(index - 1)
.addClass("now");
}
);
};
var index = 1;
var timer = setInterval(function() {
index++;
// 做动画
animateFuc();
}, 5000);
imageBox.on("swipeLeft", function() {
index++;
animateFuc();
});
imageBox.on("swipeRight", function() {
index--;
animateFuc();
});
});
一键复制
编辑
Web IDE
原始数据
按行查看
历史