zoukankan      html  css  js  c++  java
  • 无缝滚动js代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta charset="UTF-8">
    <title>无缝滚动</title>
    <style>
    * {margin: 0;padding: 0;}
    #div1{ 1600px;height: 300px;background: red; margin:100px auto;overflow: hidden;
    position: relative;}
    #div1 ul{position: absolute;left:0;}
    #div1 ul li{float: left;list-style-type: none;overflow: hidden;left: 0;
    top:0;}
    input{font-size: 20px;border: 2px solid blue;background-color: aliceblue;margin-left: 800px;}
    #div2{ 1600px;height: 300px;}
    </style>
    <script>
    window.onload=function () {
    var oDiv1=document.getElementById('div1');
    var oUl=oDiv1.getElementsByTagName('ul')[0];
    var oLi=oDiv1.getElementsByTagName('li');
    var input1=document.getElementsByTagName('input')[0];
    var input2=document.getElementsByTagName('input')[1];
    var moue=-2;
    //在图片后面再加上一次
    oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;
    oUl.style.width=oLi[0].offsetWidth*oLi.length+'px';
    function move() {
    if(oUl.offsetLeft<-oUl.offsetWidth/2){
    oUl.style.left='0';
    }else if(oUl.offsetLeft>0){
    oUl.style.left=-oUl.offsetWidth/2+'px';
    }
    oUl.style.left=oUl.offsetLeft+moue+'px';
    }

    var tem=setInterval(move,10)
    oDiv1.onmouseover=function () {
    clearInterval(tem);
    }
    oDiv1.onmouseout=function () {
    tem=setInterval(move,10)
    }
    //向左按钮
    input1.onclick=function () {
    moue=-6;
    }
    //向右按钮
    input2.onclick=function () {
    moue=6;
    }
    }
    </script>
    </head>
    <body>
    <div id="div1">
    <ul>
    <li><img src="img/m1.jpg"></li>
    <li><img src="img/m2.jpg"></li>
    <li><img src="img/m3.jpg"></li>
    <li><img src="img/m4.jpg"></li>
    <li><img src="img/m5.jpg"></li>
    <li><img src="img/m6.jpg"></li>
    <li><img src="img/m7.jpg"></li>
    <li><img src="img/m8.jpg"></li>
    </ul>

    </div>
    <div id="div2">
    <input type="button" value="向左滚动"/>
    <input type="button" value="向右滚动"/>
    </div>
    </body>
    </html>
  • 相关阅读:
    剑指offer——最小的K个数和数组中第K大的元素
    Leetcode刷题指南链接整理
    160. Intersection of Two Linked Lists
    100. Same Tree
    92. Reverse Linked List II
    94. Binary Tree Inorder Traversal
    79. Word Search
    78,90,Subsets,46,47,Permutations,39,40 DFS 大合集
    0x16 Tire之最大的异或对
    0x16 Tire
  • 原文地址:https://www.cnblogs.com/strivinghu/p/5934040.html
Copyright © 2011-2022 走看看