zoukankan      html  css  js  c++  java
  • 图片点击轮播(四)高级--2017-04-05

     点击下方图片轮播:

    关键点:onmouseover ,onmouseout两个事件;DOM;

    <style>
    #datu
    {
    400px;
    height:300px;
    position:relative;
    margin:20px auto;
    overflow:hidden;
    }
    #ta
    {
    position:relative;
    left:0px;
    top:0px;
    transition:0.7s;}
    #suo
    {
    300px;
    height:30px;
    position:relative;
    margin:20px auto;
    border:0px solid blue;
    line-height:30px;}
    .suo
    {
    30px;
    height:30px;
    position:relative;
    border:1px solid yellow;
    float:left;
    margin-left:10px;
    margin-top:10px;}
    </style>
    </head>

    <body>
    <div id="datu" onmouseover="Zhi()" onmouseout="Li()" >
    <table id="ta" cellpadding="0" cellspacing="0">
    <tr height="300">
    <td><img src="turn-pic/a.jpg" width="400" height="300"/></td>
    <td><img src="turn-pic/b.jpg" width="400" height="300" /></td>
    <td><img src="turn-pic/c.jpg" width="400" height="300" /></td>
    <td><img src="turn-pic/d.jpg" width="400" height="300"/></td>
    <td><img src="turn-pic/e.jpg" width="400" height="300"/></td>
    </tr>
    </table>
    </div>
    <div id="suo" onmouseover="Zhi()" onmouseout="Li()">
    <div class="suo" biao="1"><img src="turn-pic/a.jpg" width="30" height="30" /></div>
    <div class="suo" biao="2"><img src="turn-pic/b.jpg" width="30" height="30" /></div>
    <div class="suo" biao="3"><img src="turn-pic/c.jpg" width="30" height="30" /></div>
    <div class="suo" biao="4"><img src="turn-pic/d.jpg" width="30" height="30" /></div>
    <div class="suo" biao="5"><img src="turn-pic/e.jpg" width="30" height="30" /></div>
    </div>
    </body>
    </html>
    <script>
    document.getElementById("ta").style.left="0px";
    document.getElementsByClassName("suo").item(0).style.borderColor="red";

    var biaosuo=1;
    var suo=document.getElementsByClassName("suo");
    for(var i=0;i<suo.length;i++)
    {
    suo.item(i).onclick=function(){
    var biao = this.getAttribute("biao");
    for(var i = 0;i<5;i++)
    {
    if(i==biao-1)
    {
    document.getElementsByClassName("suo").item(i).style.borderColor="red";
    }
    else
    {
    document.getElementsByClassName("suo").item(i).style.borderColor="yellow";
    }
    if(biao==1)
    {
    document.getElementById("ta").style.left="0px";
    }
    else if(biao==2)
    {
    document.getElementById("ta").style.left="-400px";
    }
    else if(biao==3)
    {
    document.getElementById("ta").style.left="-800px";
    }
    else if(biao==4)
    {
    document.getElementById("ta").style.left="-1200px";
    }
    else
    {
    document.getElementById("ta").style.left="-1600px";
    }
    }
    }
    }

    function Change()
    {
    var ta = parseInt(document.getElementById("ta").style.left);
    if(ta>-1600)
    {
    document.getElementById("ta").style.left=(ta-400)+"px";
    ta=ta-400;
    if(ta==-400)
    {
    biaosuo=2;
    }
    else if(ta==-800)
    {
    biaosuo=3;
    }
    else if(ta==-1200)
    {
    biaosuo=4;
    }
    else if(ta=-1600)
    {
    biaosuo=5;
    }
    }
    else
    {
    document.getElementById("ta").style.left="0px";
    biaosuo=1;
    }
    for(var i = 0;i<5;i++)//offsetLeft
    {
    if(i==biaosuo-1)
    {
    document.getElementsByClassName("suo").item(i).style.borderColor="red";
    }
    else
    {
    document.getElementsByClassName("suo").item(i).style.borderColor="yellow";
    }
    }
    shi=window.setTimeout("Change()",3000);
    }
    var shi =window.setTimeout("Change()",3000);
    function Zhi()
    {
    window.clearTimeout(shi);
    }
    function Li()
    {
    shi=window.setTimeout("Change()",1000);
    }
    </script>

  • 相关阅读:
    shell 知识点
    辅助字符串处理类:org.apache.commons.lang3.StringUtils
    post请求(headers里有属性)报错:Request header field xxx is not allowed by Access-Control-Allow-Headers in preflight response
    vue-cli 打包报错:Unexpected token: punc (()
    遍历对象,并对其中第一个(随机)进行处理
    JavaScript中类似PHP的uniqid()方法
    使用crypto-js的md5加密
    Yarn、MapReduce、spark、storm的关系
    hadoop 知识点
    spring cloud 知识点
  • 原文地址:https://www.cnblogs.com/chenguanai/p/6670418.html
Copyright © 2011-2022 走看看