Effect: When the mouse moves into the picture, the scrolling stops, when the mouse moves out, it automatically scrolls Can adjust scrolling to left or right direction Copy code The code is as follows: <br> * {<br> margin: 0;<br> padding: 0;<br> }<br> #div1 {<br> overflow: hidden;<br> width: 712px;<br> Height: 108px;<br> margin: 100px auto;<br> position: relative;<br> background: red;<br> }<br> #div1 ul {<br> position: absolute;<br> left: 0;<br> top: 0;<br> }<br> #div1 ul li {<br> float: left;<br> width: 178px;<br> Height: 108px;<br> list-style: none;<br> }<br> <br> </div> <p></p> <div class="codetitle"> <span><a style="CURSOR: pointer" data="31087" class="copybut" id="copybut31087" onclick="doCopy('code31087')">Copy code<u></u></a> The code is as follows:</span><div class="codebody" id="code31087"> <br> <body><br> <a href="javascript:;">Go left</a><br> <a href="javascript:;">Go right</a><br> <div id="div1"><br> & Lt; img src = "IMG/seamless scrolling /1.jpg"/& gt; <br> </ul><br> </body><br> <br><br> <br>The above is a simple layout, and the following is the main Javascript code<br> <br><br><br><br><br>Copy code<br><br><br> The code is as follows:<br><div class="codebody" id="code9061"> <br> <script type="text/javascript"><br> window.onload = function() {<br> var oDiv = document.getElementById("div1");<br> var oUl = oDiv.getElementsByTagName('ul')[0];<br> var aLi = oUl.getElementsByTagName('li');<br> var speed = 2; <br> oUl.innerHTML = oUl.innerHTML;<br> oUl.style.width = aLi[0].offsetWidth * aLi.length 'px';<br> function move() {<br> if (oUl.offsetLeft < -oUl.offsetWidth / 2) {<br /> oUl.style.left = '0';<br /> }<br /> if (oUl.offsetLeft > 0) {<br> oUl.style.left = -oUl.offsetWidth / 2 'px';<br> }<br> oUl.style.left = oUl.offsetLeft speed 'px';<br> }<br> var timer = setInterval(move, 30);<br> oDiv.onmouseover = function() {<br> clearInterval(timer);<br> };<br> oDiv.onmouseout = function() {<br> timer = setInterval(move, 30);<br> };<br> document.getElementsByTagName('a')[0].onclick = function() {<br> speed = -2;<br> };<br> document.getElementsByTagName('a')[1].onclick = function() {<br> speed = 2;<br> };<br> }<br> </script><br> </div> <p>简单讲下思路:</p> <p>首先设置ul 里面的图片一共有8张 oUl.innerHTML = oUl.innerHTML;</p> <p>在 计算ul的宽度为 li的实际宽度*8</p> <p>之后将 多余的内容隐藏</p> <p>注意 : oUl.offsetLeft 肯定是负值</p> <p>所以判断的时候不要把负号漏掉</p> <p></p> <div class="codetitle"> <span><a style="CURSOR: pointer" data="48582" class="copybut" id="copybut48582" onclick="doCopy('code48582')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code48582"> <br> if (oUl.offsetLeft < -oUl.offsetWidth / 2) { <br> oUl.style.left = '0'; }<p> <br></p> </div> This paragraph means that the picture has been scrolled halfway, quickly pull the picture back, because the program executes too fast, so it is almost invisible to achieve seamless scrolling<p> </p>Finally, use the variable speed to control scrolling in the left and right directions. <p> </p>The above code only implements the most basic functions, and friends can continue to improve on this basis. <p></p> </div> </div>