相思资源网 Design By www.200059.com
本文整理汇总了JavaScript实现图片滚动的常见代码,可以实现向上下左右四个方向的无缝滚动的效果,这是前端设计开发时常用的一个图片特效,你可只用其中的一种滚动效果。
具体的实例代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN"> <head> <title>图片滚动代码合集</title> <script type="text/javascript"> // 自动滚动 function boxmove(d1,d2,d3,e,obj){ var speed=30; var demo=document.getElementById(d1); var demo1=document.getElementById(d2); var demo2=document.getElementById(d3); demo2.innerHTML=demo1.innerHTML; function boxTop(){ if(demo2.offsetTop-demo.scrollTop<=0){demo.scrollTop-=demo1.offsetHeight} else{demo.scrollTop++} } function boxRight(){ if(demo.scrollLeft<=0){demo.scrollLeft+=demo2.offsetWidth} else{demo.scrollLeft--} } function boxBottom(){ if(demo1.offsetTop-demo.scrollTop>=0){demo.scrollTop+=demo2.offsetHeight} else{demo.scrollTop--} } function boxLeft(){ if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth} else{demo.scrollLeft++} } if(e==1){ var MoveTop=setInterval(boxTop,speed); demo.onmouseover=function(){clearInterval(MoveTop);} demo.onmouseout=function(){MoveTop=setInterval(boxTop,speed)} } if(e==2){ var MoveRight=setInterval(boxRight,speed); demo.onmouseover=function(){clearInterval(MoveRight)} demo.onmouseout=function(){MoveRight=setInterval(boxRight,speed)} } if(e==3){ var MoveBottom=setInterval(boxBottom,speed); demo.onmouseover=function(){clearInterval(MoveBottom);} demo.onmouseout=function(){MoveBottom=setInterval(boxBottom,speed)} } if(e==4){ var MoveLeft=setInterval(boxLeft,speed) demo.onmouseover=function(){clearInterval(MoveLeft)} demo.onmouseout=function(){MoveLeft=setInterval(boxLeft,speed)} } if(e=="top"){ MoveTop=setInterval(boxTop,speed) obj.onmouseout=function(){clearInterval(MoveTop);} } if(e=="right"){ MoveRight=setInterval(boxRight,speed) obj.onmouseout=function(){clearInterval(MoveRight);} } if(e=="bottom"){ MoveBottom=setInterval(boxBottom,speed) obj.onmouseout=function(){clearInterval(MoveBottom);} } if(e=="left"){ MoveLeft=setInterval(boxLeft,speed) obj.onmouseout=function(){clearInterval(MoveLeft);} } } </script> <style type="text/css"> div#a,div#b,div#c,div#d { float:left;} h2 { clear:both; } div#b,div#d,div#bb { white-space:nowrap; } </style> </head> <body> <h1>滚动合集</h1> <hr /> <h2>向上</h2> <div id="a" style="overflow:hidden;height:100px;width:90px;"> <div id="a1"> <img src="/UploadFiles/2021-04-02/logo.gif1">
标签:
JS,图片,无间断,滚动,代码
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无JS实现图片无间断滚动代码汇总的评论...