老师,为啥越播越快
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/index.css">
<title>Document</title>
</head>
<body>
<div class="main" id="main">
<!-- 轮播图部分 -->
<div class="banner" id="banner">
<a href="">
<div class="banner-slide slide1 slide-active"></div>
</a>
<a href="">
<div class="banner-slide slide2 "></div>
</a>
<a href="">
<div class="banner-slide slide3"></div>
</a>
</div>
<!-- 上一张,下一张按钮 -->
<a href="javascript:void(0)" class="btn prve"></a>
<a href="javascript:void(0)" class="btn next"></a>
<!-- 远点按钮 -->
<div class="dots">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
<script src="js/index.js"></script>
</body>
</html>
*{
margin:0;
padding:0;
}
body{
font-family: "Microsoft YaHei";
font-size:16px;
}
.main{
width:1200px;
height:460px;
margin:30px auto;
overflow: hidden;
position: relative;
}
.banner{
width:1200px;
height:460px;
position: relative;
overflow: hidden;
}
.banner-slide{
width:1200px;
height:460px;
background-repeat: no-repeat;
float:left;
display: none;
}
.slide1{
background-image: url(../images/bg1.jpg);
}
.slide2{
background-image: url(../images/bg2.jpg);
}
.slide3{
background-image: url(../images/bg3.jpg);
}
.slide-active{
display: block;
}
.btn{
width: 40px;
height:80px;
position:absolute;
transform: rotate(180deg);
top:50%;
left:244px;
margin-top:-40px;
background: url(../images/arrow.png) center center no-repeat;
}
.btn:hover{
background-color: #333;
opacity: 0.8;
}
.next{
left:auto;
right:0;
transform: rotate(0deg);
}
.dots{
position:absolute;
bottom:24px;
right:20px;
}
.dots span{
display: inline-block;
width: 12px;
height:12px;
border-radius: 50%;
background-color: #333;
box-shadow: 0 0 2px #fff inset;
margin-right: 8px;
}
.dots span.active{
background-color: #fff;
box-shadow: 0 0 2px #333 inset;
}
function byId(id){
return typeof(id)==="string"?document.getElementById(id):id;
}
var timer=null,
index=0,
pics=byId("banner").getElementsByTagName("div"),
len=pics.length;
function slideImg(){
var main=byId("main");
main.onmouseover=function(){
}
main.onmouseout=function(){
timer=setInterval(function(){
index++;
if(index>=len){
index=0;
}
changeImg();
},3000);
}
main.onmouseout();
}
function changeImg(){
for(var i=0;i<len;i++){
pics[i].style.display="none";
}
pics[index].style.display="block";
}
slideImg();
正在回答 回答被采纳积分+1
谢谢老师啦
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36713 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星