html京东自动轮播代码生成器,原生JS京东轮播图代码

.jiantou {

height: 36px;

width: 24px;

line-height: 36px;

text-align: center;

background-color: rgba(0, 0, 0, .3);

font-size: 14px;

color: #fff;

position: absolute;

top: 0;

bottom: 0;

margin: auto 0;

display: none;

z-index: 99999;

cursor: pointer;

}

.left {

left: 0;

}

.right {

right: 0;

}

ul li {

height: 20px;

width: 20px;

background-color: #B7B7B7;

float: left;

border-radius: 50%;

margin: 2px;

}

ul {

position: absolute;

bottom: 15px;

margin: 0 auto;

background-color: rgba(255, 255, 255, .3);

border-radius: 10px;

left: 300px;

z-index: 9999;

cursor: pointer;

}

.on {

background-color: #F40;

}

img {

width: 790px;

height: 340px;

position: absolute;

opacity: 0;

/*transition: all 2s;*/

/*transition: all 0.5s;*/ /*时间给短一些*/

transition: opacity 0.5s; /*不要写all 那么就不会影响到z-index*/

z-index: 0;

}

.in {

width: 790px;

height: 340px;

}

#out {

width: 790px;

height: 340px;

margin: 100px auto;

position: relative;

}

#out:hover .jiantou {

display: block;

}

<
>

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

if(i<5){

arr.push(img[i].offsetHeight);

}else {

img[i].style.position='abl'

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基本的 HTML 片自动轮代码: ```html <!DOCTYPE html> <html> <head> <title>片自动轮</title> <style> .slideshow-container { max-width: 500px; position: relative; margin: auto; } .mySlides { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; } .slideshow-container img { width: 100%; height: 100%; } .dot-container { text-align: center; margin: 20px 0; } .dot { height: 15px; width: 15px; margin: 0 5px; border-radius: 50%; display: inline-block; background-color: #bbb; transition: background-color 0.5s ease; cursor: pointer; } .active, .dot:hover { background-color: #717171; } </style> </head> <body> <div class="slideshow-container"> <img class="mySlides" src="img1.jpg"> <img class="mySlides" src="img2.jpg"> <img class="mySlides" src="img3.jpg"> <div class="dot-container"> <span class="dot" onclick="currentSlide(1)"></span> <span class="dot" onclick="currentSlide(2)"></span> <span class="dot" onclick="currentSlide(3)"></span> </div> </div> <script> var slideIndex = 1; showSlides(slideIndex); function plusSlides(n) { showSlides(slideIndex += n); } function currentSlide(n) { showSlides(slideIndex = n); } function showSlides(n) { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); if (n > slides.length) {slideIndex = 1} if (n < 1) {slideIndex = slides.length} for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; setTimeout(showSlides, 3000); // 切换片的时间间隔,单位为毫秒 } </script> </body> </html> ``` 这个代码使用了 JavaScript 来实现自动轮,每隔 3 秒钟就自动切换片。你可以根据自己的需求来修改切换时间间隔等参数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值