简单实现js无缝滚动效果
程序员文章站
2022-06-08 15:38:28
本文实例为大家分享了js无缝滚动效果的具体代码,供大家参考,具体内容如下
本文实例为大家分享了js无缝滚动效果的具体代码,供大家参考,具体内容如下
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>document</title> <style> *{ margin: 0; padding: 0; } ul{ list-style: none; } img{ vertical-align: top; /*消除3px的距离*/ } .box{ width: 600px; height: 200px; margin: 100px auto; overflow: hidden; position: relative; border: 1px solid red; } ul{ width: 400%; position: absolute; left: 0; top: 0; } ul li{ float: left; } </style> <script> window.onload = function(){ function $(id){ return document.getelementbyid(id); } var timer = null; var num = 0; timer = setinterval(autoplay,20); function autoplay(){ num--; if(num<=-1200){ num = 0; } $("picbox").style.left = num + "px"; } $("picbox").onmouseover = function(){ clearinterval(timer); } $("picbox").onmouseout = function(){ timer = setinterval(autoplay,20); } } </script> </head> <body> <div class="box" id="scroll"> <ul id="picbox"> <li><img src="images/01.jpg" alt=""></li> <li><img src="images/02.jpg" alt=""></li> <li><img src="images/03.jpg" alt=""></li> <li><img src="images/04.jpg" alt=""></li> <li><img src="images/01.jpg" alt=""></li> <li><img src="images/02.jpg" alt=""></li> </ul> </div> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。