代码无法实现js效果,请问是有什么问题
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery作业</title>
<link rel="stylesheet" type="text/css" href="css/jq.css">
</head>
<body>
<div calss="title"><h2>jQuery实现轮播图</h2></div>
<div class="main" id="main">
<div class="slide img1 s-active"><img src="img/1.jpg"></div>
<div class="slide img2"><img src="img/2.jpg"></div>
<div class="slide img3"><img src="img/3.jpg"></div>
<div class="slide img4"><img src="img/4.jpg"></div>
<div class="slide img5"><img src="img/5.jpg"></div>
<a href="javascript:void(0)" class="btn pre"></a>
<a href="javascript:void(0)" class="btn next"></a>
<div class="dots">
<span class="d-active"></span>
<span ></span>
<span ></span>
<span ></span>
<span ></span>
</div>
</div>
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
$(function(){
var timer=null,
main=$('.main'),
dots=$('span'),
pre=$('.pre'),
next-$('.next'),
slide=$('.slide'),
index=0,
len=slide.length;
function slideImg(){
//自动轮播
function start(){
timer=setInterval(function(){
index++;
if(index>=len){
index=0;
}
changeImg();
},2000);
}
start();
//停播
function stop(){
if(timer) clearInterval(timer);
}
main.on('mouseout',function(){
start();
});
main.om('mouseover',function(){
stop();
});
//后退
pre.on('click',function(){
index--;
if(index<0){
index=len-1;
}
changeImg();
});
//前进
next.on('click',function(){
index++;
if(index>=len){
index=0;
}
changeImg();
});
//圆点
dots.on('click',function(){
index=$(this).index();
changeImg();
});
//切换图片函数
function changeImg(){
slide.removeClass('s-active');
dots.removeClass('d-active');
slide.eq(index).addClass('s-active');
dots.eq(index).addClass('d-active');
}
}
slideImg();
});
</script>
</body>
</html>0
收起
正在回答 回答被采纳积分+1
3回答
慕码人5074091
2018-09-07 12:41:00
*{
padding:0;
margin:0;
}
body{
font-family: "微软雅黑";
color: #14191e;
}
.main{
width: 1200px;
height: 460px;
margin:50px auto;
overflow: hidden;
border:5px solid #bbb;
position: relative;
}
.title{
height:50px;
}
h2{
font-family:"微软雅黑";
text-align:center;
line-height:50px;
}
.slide{
width: 1200px;
height: 460px;
background-repeat: no-repeat;
position: absolute;
display: none;
}
.s-active{
display: block;
}
.btn{
position: absolute;
width: 30px;
height: 60px;
left: 0px;
top:255px;
margin-top:-40px;
background: url("../img/pre2.png") no-repeat center center;
}
.btn:hover{
background-color: #333;
opacity: 0.5;
}
.next{
left: auto;
right:0px;
background: url("../img/pre.png") no-repeat center center;
}
.dots{
position: absolute;
right: 10px;
bottom: 0px;
text-align: center;
}
.dots span{
display: inline-block;
width: 12px;
height:12px;
border-radius: 50%;
background:rgba(7,17,27,0.4);
box-shadow: 0 0 0 1px rgba(255,255,255,0.7);
margin-left:8px;
}
.dots span.d-active{
box-shadow: 0 0 0 1px rgba(7,17,27,0.4);
background:#fff;
}
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程



恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星