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" lang="utf-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无缝滚动图片示例-F-BLOG</title> <style type="text/css"> ul{list-style:none;padding:0px;margin:0px;} #demo1 ul,#demo2 ul{width:400px;} #demo1 li,#demo2 li{float:left;} </style> <script type="text/javascript"> function $(id){ return document.getElementById(id); } function Marquee(id,toFollow,speed) { var doScroll; var scrollBox_x="<table cellpadding='0' cellspacing='0'><tr><td>"+$(id).innerHTML+"</td><td>"+$(id).innerHTML+"</td></tr></table>"; var scrollBox_y="<table cellpadding='0' cellspacing='0'><tr><td>"+$(id).innerHTML+"</td></tr><tr><td>"+$(id).innerHTML+"</td></tr></table>"; var begin=function(){ switch(toFollow){ case "left": $(id).innerHTML=scrollBox_x; doScroll=setInterval(function(){ if($(id).scrollLeft==$(id+"abox").offsetWidth) $(id).scrollLeft=0; $(id).scrollLeft++; },speed); break; case "right": $(id).innerHTML=scrollBox_x; doScroll=setInterval(function(){ if($(id).scrollLeft<=0) $(id).scrollLeft=$(id+"bbox").offsetWidth; $(id).scrollLeft--; },speed); break; case "top": $(id).innerHTML=scrollBox_y; doScroll=setInterval(function(){ if($(id).scrollTop==$(id+"abox").offsetHeight) $(id).scrollTop=0; $(id).scrollTop++; },speed); break; case "bottom": $(id).innerHTML=scrollBox_y; doScroll=setInterval(function(){ if($(id).scrollTop<=0) $(id).scrollTop=$(id+"bbox").offsetHeight; $(id).scrollTop--; },speed); break; } } begin(); $(id).onmouseover=function() {clearInterval(doScroll);} $(id).onmouseout=function() {begin();} } window.onload=function(){ Marquee("demo2","left",30); Marquee("demo1","right",20); Marquee("demo3","top",30); Marquee("demo4","bottom",30); } </script> </head> <body> <div> <ul> <li><img src="https://www.jb51.net/article/mm.jpg" mce_src="https://www.jb51.net/article/mm.jpg" /></li> <li><img src="https://www.jb51.net/article/me.jpg" mce_src="https://www.jb51.net/article/me.jpg" /></li> </ul> </div> <br/> <div> <ul> <li><img src="https://www.jb51.net/article/mm.jpg" mce_src="https://www.jb51.net/article/mm.jpg" /></li> <li><img src="https://www.jb51.net/article/me.jpg" mce_src="https://www.jb51.net/article/me.jpg" /></li> </ul> </div> <br/> <div> <ul> <li><img src="https://www.jb51.net/article/mm.jpg" mce_src="https://www.jb51.net/article/mm.jpg" /></li> <li><img src="https://www.jb51.net/article/me.jpg" mce_src="https://www.jb51.net/article/me.jpg" /></li> </ul> </div> <br/> <div> <ul> <li><img src="https://www.jb51.net/article/mm.jpg" mce_src="https://www.jb51.net/article/mm.jpg" /></li> <li><img src="https://www.jb51.net/article/me.jpg" mce_src="https://www.jb51.net/article/me.jpg" /></li> </ul> </div> </body> </html>

更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript切换特效与技巧总结》、《JavaScript查找算法技巧总结》、《JavaScript动画特效与技巧汇总》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript遍历算法与技巧总结》及《JavaScript数学运算用法总结

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwyfs.html