js淡入淡出轮播

本文介绍了一种使用HTML和CSS实现的简单图集轮播效果。通过设置定时器自动切换图片显示,并利用鼠标悬停事件暂停轮播。此外,还提供了手动导航按钮以便用户控制图片切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style>
body, div, ul, li{margin:0; padding:0;}
ul{list-style-type: none;}
body{background:#000; text-align: center;}
#box {position: relative;width: 492px;height: 172px;background: #fff;border-radius: 5px;border: 8px solid #fff; margin: 10px auto;}
#box .list{position: relative;width: 490px;height: 170px; overflow: hidden; border: 1px solid #ccc;}
#box .list li {position: absolute;top: 0;left: 0;width: 490px; height: 170px;}
#box .count {position: absolute;right: 0;bottom: 5px;}
#box .count li {color: #fff;float: left;width: 20px;height: 20px;cursor: pointer;margin-right: 5px;overflow: hidden;background: #F90;border-radius:20px; cursor:pointer;}
#box .count li.current {color:#fff; font-weight:700; background:#f60;}
#box .left{position:absolute; top:60px; left:0; font-size:20px; cursor:pointer;}
#box .right{position:absolute; top:60px; right:0px; font-size:20px; cursor:pointer;}
</style>
</head>
<body>
<div id="box">
 <ul class="list">
<li style="display:block;"><img src="images/1.jpg" width="490" height="170"></li>
<li style="display:none;"><img src="images/2.jpg" width="490" height="170"></li>
<li style="display:none;"><img src="images/3.jpg" width="490" height="170"></li>
 </ul>
 <ul class="count">
<li class="current">1</li>
<li>2</li>
<li>3</li>
 </ul>
<h2 class="left"> < </h2>
<h2 class="right"> > </h2>
</div>
<script>
var box=document.getElementById('box');
var uls=document.getElementsByTagName('ul');
var imgs=uls[0].getElementsByTagName('li');
var btn=uls[1].getElementsByTagName('li');
var header=box.getElementsByTagName('h2');
for(i=0; i<btn.length; i++){
btn[i].index=i;
btn[i].onmouseover=function(){
for(var j=0;j<btn.length; j++){
btn[j].className="";
imgs[j].style.display="none";
};
this.className="current";
i=this.index;
imgs[i].style.display="block";
};
};
var i=0;
function abc(){
if(i==imgs.length){
i=0;
};
if(i==-1){
i=imgs.length-1;
};
for(var j=0;j<btn.length; j++){
btn[j].className="";
imgs[j].style.display="none";
};
btn[i].className="current";
imgs[i].style.display="block";
};
dd=setInterval(function(){
i++;
abc();
},2000);
header[0].onclick=function(){
i--;
abc();
};
header[1].onclick=function(){
i++;
abc();
};
box.onmouseover=function(){
clearInterval(dd);
};
box.onmouseout=function(){
dd=setInterval(function(){
i++;
abc();
},2000);
};
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值