老师,请您帮忙来检查一下代码,谢谢!
来源:6-3 编写跑马灯轮播图特效
慕粉1924517932
2021-12-12 15:23:11
问题描述:
老师为什么我做的效果跟视频当中的不是很一样,请您出手检查一下,谢谢
相关代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ padding:0px; margin:0px; } .box{ width:650px; height:360px; margin:50px auto; border: 1px solid #000; position: relative; overflow: hidden; } .box ul{ width:5000px; list-style: none; left:0px; position: relative; transition: left .5s ease 0s; } .box ul li{ float:left; } .leftbtn{ width:30px; height:30px; background-color: red; border: 1px solid #000; text-decoration: none; border-radius: 50%; position: absolute; left:20px; top:50%; margin-top:-25px; font-size: 25px; color:white; text-align: center; line-height: 30px; } .rightbtn{ width:30px; height:30px; background-color: red; border: 1px solid #000; text-decoration: none; border-radius: 50%; position: absolute; right:20px; top:50%; margin-top:-25px; font-size: 25px; color:white; text-align: center; line-height: 30px; } </style> </head> <body> <div class="box"id="box"> <ul class="list"id="list"> <li><img src="image/hudie.jpg"width="650px"height="360px"></li> <li><img src="image/huoshaoyun.jpg"width="650px"height="360px"></li> <li><img src="image/jiudian.jpg"width="650px"height="360px"></li> <li><img src="image/shanshui.jpg"width="650px"height="360px"></li> <li><img src="image/wangzixuan1.jpg"width="650px"height="360px"></li> </ul> <a href="javascript:;"class="leftbtn"id="leftbtn"><</a> <a href="javascript:;"class="rightbtn"id="rightbtn">></a> </div> </body> <script> var leftbtn=document.getElementById('leftbtn'); var rightbtn=document.getElementById('rightbtn'); var list=document.getElementById('list'); var cloneli=list.firstElementChild.cloneNode(true); list.appendChild(cloneli); //当前ul显示到第几章了了,从0开始数 var idx=0; //节流锁 var lock=true; //监听 rightbtn.onclick=function(){ if(!lock) return; lock=false; //给list加过渡,为什么还要再加一边过渡属性是因为最后一张图片会把过渡去掉 list.style.transition='left .5 ease 0s' idx++; if(idx>4){ //设置一个延时器,功能是将ul瞬间拉回0的位置 setTimeout(function(){ //取消过度,因为要让他进行瞬间移动 list.style.transition='none' list.style.left=0; idx=0; },500); } list.style.left=-idx*650+'px'; //函数节流 setTimeout(function(){ lock=true; },500); } leftbtn.onclick=function(){ if(!lock) return; lock=false; if(idx==0){ list.style.transition='none'; list.style.left=-5*650+'px'; idx=5; //设置一个延时器,延时时间为0毫秒 setTimeout(function(){ list.style.transition='left .5 ease 0s'; idx=4; list.style.left=-idx*650+'px'; },0); }else{ idx--; list.style.left=-idx*650+'px'; } //函数节流 setTimeout(function(){ lock=true; },500); }
1回答
好帮手慕慕子
2021-12-12
同学你好,因为设置transition属性值,里面的时间没有添加单位s,导致无法实现效果,添加上就好了,如下:
祝学习愉快~
相似问题
回答 1
回答 1
回答 1
回答 1
回答 1