问题描述
- 怎样实现js左右按钮,还有当鼠标离开时图片继续播放,各位大神帮忙解决一下,没有悬赏不好意思噢
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> *{margin:0;padding:0;} ul,li,img{margin:0;padding:0;border:0;list-style-type:none;} #list{height:250px;list-style-type:none;overflow:hidden;} #luanpo{max-width:789px;height:366px;border:1px solid #CCC;margin:0 auto;position:relative;overflow:hidden;} #imgs li{float:left;height:366px;width:789px; text-align:center;} #imgs{height:366px;background:#ddd;position:absolute;} .a{background:red;} .b{background:yellow;} #num{overflow:auto;position:absolute;bottom:0; margin-left:300px;} #num li{float:left;height:30px;width:30px;text-align:center; border-radius:40px;line-height:30px;border:1px solid #CCC;margin-left:10px;cursor:pointer;z-index:2222;} #luanpo h1.h1{position:absolute; top:150px; left:20px; height:40px; width:40px; text-align:center; background-color:#F00; background:rgba(204,204,204,0.5); color:#FFF; display:block; overflow:hidden;} #luanpo h1.h2{position:absolute; top:150px; right:20px; height:40px; width:40px; text-align:center; background-color:#F00; background:rgba(204,204,204,0.5); color:#FFF; display:block; overflow:hidden; } .h1:hover ,.h2:hover {opacity:0.5;filter:alpha(opacity=50);} </style> <body> <div id="luanpo"> <ul id="imgs"> <li><img src="images/11.jpg" width="789" height="366" /></li> <li><img src="images/22.jpg" width="789" height="366" /></li> <li><img src="images/33.jpg" width="789" height="366" /></li> <li><img src="images/44.jpg" width="789" height="366" /></li> </ul> <ul id="num"> <li class="a">1</li> <li class="b">2</li> <li class="b">3</li> <li class="b">4</li> </ul> <h1 class="h1" id="back"><</h1> <h1 class="h2" id="forward">></h1> </div> <script type="text/javascript"> var imgs=document.getElementById('imgs').getElementsByTagName('li');//当前播放的图片或者文字 var nums=document.getElementById("num").getElementsByTagName("li");//当前播放的编号 var luanpo=document.getElementById("luanpo");//获取div框架的内容 var oimg=document.getElementById('imgs');//获取div里面ul的内容 var hs=document.getElementById('back');//左右按钮 var hse=document.getElementById('forward'); var iNow=0; var dt=null; oimg.style.width=imgs.length*imgs[0].offsetWidth+"px"; //手动播放 function tab(){ for(var i=0;i<nums.length;i++){ nums[i].index=i; nums[i].onclick=function(){ clearInterval(dt); iNow=this.index; for(var i=0;i<nums.length;i++){ nums[i].className="b"; } this.className="a"; oimg.style.left=-(imgs[0].offsetWidth*iNow)+"px"; //缓动框架 } nums[i].onmouseout=function(){ start(); } } } //自动播放 function start(){ clearInterval(dt); dt=setInterval(function(){ if(iNow>nums.length-2){ iNow=0; }else{ iNow++; } for(var k=0;k<nums.length;k++){ if(iNow==nums[k].index){nums[k].className='a';}else{nums[k].className='b';} } oimg.style.left=-(imgs[0].offsetWidth*iNow)+"px"; //缓动框架 },2000); luanpo.onmouseover = function(){ clearInterval(dt); } luanpo.onmouseout=function(){ dt=setInterval(tab,2000); } tab(); } start(); </script> </body> </html>
解决方案
参考:http://www.17sucai.com/preview/118194/2015-07-10/fullscreen-drag-slider-with-parallax/index.html
解决方案二:
代码没有格式化 看起来好蛋疼。。。。。。。
时间: 2024-08-18 05:14:38