xinxinfangyan 2015-08-31 07:49 采纳率: 0%
浏览 1720

怎样实现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>

  • 写回答

2条回答 默认 最新

  • 毕小宝 博客专家认证 2015-08-31 08:06
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊