zoukankan      html  css  js  c++  java
  • 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>
    *{
        margin:0px;
        padding:0px;
    }
    #cute
    {
        position:relative;
        1400px;
        height:220px;
        margin-top:100px;
        margin-left:120px;
        overflow:hidden;
    }
    #cute ul
    {
        list-style-type:none;
        left:0px;
        top:0px;
        position:absolute;
    }
    #cute ul li
    {
        float:left;
        margin-left:5px;
    }
    li img
    {
        270px;
        height:220px;
    }
    #right
    {
        float:right;
    }
    </style>
    <script>
    window.onload=function()
    {
        var oCte=document.getElementById('cute');
        var oUl=oCte.getElementsByTagName('ul')[0];
        var aLi=oUl.getElementsByTagName('li');
        var speed=2;
        oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
        oUl.style.width=aLi[0].offsetWidth*aLi.length+50+'px';
        function move()
        {
            if (oUl.offsetLeft<-oUl.offsetWidth/2)
                oUl.style.left='0px';       
            if (oUl.offsetLeft>0)
                oUl.style.left=-oUl.offsetWidth/2+'px';
            oUl.style.left=oUl.offsetLeft+speed+'px';
        }
        var timer=setInterval(move, 30);
        oCte.onmouseover=function()
        {
            clearInterval(timer);
        };
        oCte.onmouseout=function()
        {
            timer=setInterval(move, 30);
        };
        document.getElementById('left').onclick=function()
        {
            speed=-2;
        };
        document.getElementById('right').onclick=function()
        {
            speed=2;
        };
    };
    </script>
    </head>
    <body>
    <div id="left">
    <img src="image/left.jpg"/>
    </div>
    <div id="cute">
        <ul>
            <li><img src="image/a.jpg"/></li>
            <li><img src="image/b.jpg"/></li>
            <li><img src="image/c.jpg"/></li>
            <li><img src="image/d.jpg"/></li>
            <li><img src="image/e.jpg"/></li>
        </ul>
    </div>
    <div id="right">
    <img src="image/right.jpg"/>
    </div>
    </body>
    </html>                    
  • 相关阅读:
    有个表叫杨表(上)
    Codeforces Round #698 (Div. 2) 题解 全部6题
    Leetcode 821. 字符的最短距离
    gitbook mermaid不能渲染问题
    adb命令启动app及查找系统版本号
    git库使用
    excle转html方法
    gitbook插入视频
    xcode使用技巧
    在 Mac 上的“自动操作”工作流程中使用 Shell 脚本操作
  • 原文地址:https://www.cnblogs.com/syhandll/p/5042940.html
Copyright © 2011-2022 走看看