原生JS京东轮播图代码

前端之家收集整理的这篇文章主要介绍了原生JS京东轮播图代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例为大家分享了JS轮播图的具体代码,供大家参考,具体内容如下

Meta charset="UTF-8">
@H_502_25@ var out = document.getElementById("out"); var img = document.images; var left = document.getElementsByClassName("left").item(0); var right = document.getElementsByClassName("right").item(0); var lilist = document.getElementsByTagName("li"); var index = 0;//标识哪张图片正在出现 var timer = null; var timer1 = null;

right.onclick = function () {
//把所有人的opacity置为0
/for (var i = 0; i < img.length; i++) {
img[i].style.opacity = 0;
}
/
img[index].style.opacity = 0;
img[index].style.zIndex = 0;
lilist[index].className = '';
// index++;
index == 7 ? index = 0 : index++;
lilist[index].className = 'on';
img[index].style.opacity = 1;
img[index].style.zIndex = 1;

};

left.onclick = function () {
img[index].style.opacity = 0;
lilist[index].className = '';
img[index].style.zIndex = 0;
// index--;
index == 0 ? index = 7 : index--;
lilist[index].className = 'on';
img[index].style.opacity = 1;
img[index].style.zIndex = 1;
};

for (var i = 0; i < lilist.length; i++) {
lilist[i].value = i;
lilist[i].onmouSEOver = function () {
var that = this;
timer=setTimeout(function () {
img[index].style.opacity = 0;
lilist[index].className = '';
img[index].style.zIndex = 0;

index = that.value;

lilist[index].className = 'on';
img[index].style.opacity = 1;
img[index].style.zIndex = 1;
},300)
};
lilist[i].onmouSEOut = function () {
clearTimeout(timer);
}
}
out.onclick = function (e) {
console.log(e.target);
};
timer1 = setInterval(right.onclick,2000);
out.onmouSEOver = function () {
clearInterval(timer1);
};
out.onmouSEOut = function () {
timer1 = setInterval(right.onclick,2000);
};
var num =5
var arr = [];
var img =document.images;
for(var i=0;i<img.length;i++){
if(i<5){
arr.push(img[i].offsetHeight);
}else {
img[i].style.position='abl'
}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

原文链接:https://www.f2er.com/js/40522.html

猜你在找的JavaScript相关文章