|
@@ -253,9 +253,12 @@
|
|
|
var oArrRight = document.getElementsByClassName("arr-right")[0];
|
|
var oArrRight = document.getElementsByClassName("arr-right")[0];
|
|
|
// 获取向左按钮
|
|
// 获取向左按钮
|
|
|
var oArrLeft = document.getElementsByClassName("arr-left")[0];
|
|
var oArrLeft = document.getElementsByClassName("arr-left")[0];
|
|
|
-
|
|
|
|
|
|
|
+ // 获取整个轮播图区域
|
|
|
|
|
+ var oContainer = document.getElementsByClassName("container")[0];
|
|
|
// 定义全局变量 当前是第几张图片 的索引
|
|
// 定义全局变量 当前是第几张图片 的索引
|
|
|
var curIndex = 0;
|
|
var curIndex = 0;
|
|
|
|
|
+ // 定义定时器变量
|
|
|
|
|
+ var timer = null;
|
|
|
|
|
|
|
|
// 定义切换图片函数
|
|
// 定义切换图片函数
|
|
|
function switchImg(index) {
|
|
function switchImg(index) {
|
|
@@ -283,7 +286,7 @@
|
|
|
// this.classList.add("active");
|
|
// this.classList.add("active");
|
|
|
// // 给相对应图片添加选中状态
|
|
// // 给相对应图片添加选中状态
|
|
|
// aImgItems[this.index].classList.add("active");
|
|
// aImgItems[this.index].classList.add("active");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 调用切换图片函数
|
|
// 调用切换图片函数
|
|
|
switchImg(this.index);
|
|
switchImg(this.index);
|
|
|
// 更新当前索引值
|
|
// 更新当前索引值
|
|
@@ -312,6 +315,22 @@
|
|
|
// 调用切换图片函数
|
|
// 调用切换图片函数
|
|
|
switchImg(curIndex);
|
|
switchImg(curIndex);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 实现定时轮播
|
|
|
|
|
+ function play() {
|
|
|
|
|
+ timer = setInterval(function () {
|
|
|
|
|
+ oArrRight.onclick();
|
|
|
|
|
+ }, 2000);
|
|
|
|
|
+ }
|
|
|
|
|
+ play();
|
|
|
|
|
+
|
|
|
|
|
+ // 鼠标移入停止轮播 停止轮播
|
|
|
|
|
+ oContainer.onmouseover = function () {
|
|
|
|
|
+ clearInterval(timer);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 鼠标移出开始轮播
|
|
|
|
|
+ oContainer.onmouseout = function () {
|
|
|
|
|
+ play();
|
|
|
|
|
+ }
|
|
|
</script>
|
|
</script>
|
|
|
</body>
|
|
</body>
|
|
|
|
|
|