• 10 图片无缝滚动


    功能:几张图片会向左或向右滚动,鼠标移进移出会停止和继续,点击按钮会切换左右滚动方向

    事件:onmouseover,onmouseout,onclick

    属性:ul的left,width

    用到了计时器,innerHTML,offsetLeft,offsetWidth

    oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';

    oUl.style.left=oUl.offsetLeft+speed+'px';

    ////////////

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">

    <link href="css1.css" rel="stylesheet" type="text/css"
    charset="UTF-8">
    </head>
    <body>
    <a href="javascript:;">向左走</a>
    <a href="javascript:;">向右走</a>
    <div id="div1">
    <ul>
    <li><img src="img/0.png"/></li>
    <li><img src="img/1.png"/></li>
    <li><img src="img/2.png"/></li>
    <li><img src="img/3.png"/></li>
    <li><img src="img/4.png"/></li>
    </ul>
    </div>
    <script src="js1.js"> </script>
    </body>
    </html>

    //////////////css

    *{

    margin:0;
    padding:0;
    }

    #div1{
    1000px;
    height:100px;
    background:yellow;
    position:relative;
    margin:100px auto;
    overflow: hidden;
    }
    #div1 ul{
    top:0;
    left:0;
    position:absolute;

    }
    #div1 ul li{
    200px;
    height:100px;

    list-style:none;
    float:left;
    }


    #div1 ul li img{
    200px;
    height:100px;

    }

    ////////////////js

    window.onload=function(){

    var oDiv=document.getElementById("div1");
    var oUl=oDiv.getElementsByTagName("ul")[0];
    var aLi=oUl.getElementsByTagName("li");
    var aBtn1=document.getElementsByTagName("a")[0];
    var aBtn2=document.getElementsByTagName("a")[1];
    var speed=2;

    oUl.innerHTML+=oUl.innerHTML;
    oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';
    var timer=null;
    function gogo(){
    //Left小写了
    if(oUl.offsetLeft<-oUl.offsetWidth/2){
    oUl.style.left='0';
    }
    if(oUl.offsetLeft>0){
    oUl.style.left=-oUl.offsetWidth/2+'px';
    }
    oUl.style.left=oUl.offsetLeft+speed+'px';
    };
    timer=setInterval(gogo,50);
    oUl.onmouseover=function(){
    clearInterval(timer);
    };
    oUl.onmouseout=function(){
    timer=setInterval(gogo,50);
    };
    aBtn1.onclick=function(){
    speed=-2;
    };
    aBtn2.onclick=function(){
    speed=2;
    };
    };

  • 相关阅读:
    VS2013 快捷键乱掉如何修改回来
    WCF契约之---服务契约 、数据契约、 消息契约
    成功的背后!(给所有IT人)----转载:来自CSDN第一名博主
    C# Attribute(特性)之---契约---[ServiceContract] 、 [OperationContract]
    SQL Server数据库连接字符串整理
    大写String和小写string的区别
    C#经典之Application.DoEvents()的使用
    C#实现多态之一抽象
    C# Attribute(特性)之---数据契约 [DataContract]
    Druid数据库连接池获取连接阻塞(转载)
  • 原文地址:https://www.cnblogs.com/luxiaoli/p/8520163.html
Copyright © 2020-2023  润新知