jQuery实现文字自动横移
效果图:
实现文字自动横移
<style type="text/css"> #demo {overflow:scroll;width:740px; } #indemo { float: left; width: 800%;} #demo1 { float: left; } #demo2 { float: left;margin-left:7px;} </style> <script src="bootstrap-3.3.5-dist/js/jquery-1.11.3.js"></script> <div id="demo"> <div id="indemo"> <div id="demo1"> <a href="#"><img src="zhuanpan/images/pointer.png" alt="#" /></a> <a href="#"><img src="zhuanpan/images/pointer.png" alt="#" /></a> <a href="#"><img src="zhuanpan/images/pointer.png" alt="#" /></a> </div> <div id="demo2"></div> </div> </div> 一 采用jquery方式实现文字横移 <script> var speed=20; $("#demo2").html($("#demo1").children().clone()); var n=0; function Marquee(){ if(n>=$("#demo").innerWidth()) n=0; else{ n++; } $("#demo").scrollLeft( n ); } var MyMar=setInterval(Marquee,speed); $("#demo").mouseover(function(){clearInterval(MyMar)}); $("#demo").mouseout(function(){MyMar=setInterval(Marquee,speed)}); </script> 二 采用原生script实现横移 <script> var speed=10; var tab=document.getElementById("demo"); var tab1=document.getElementById("demo1"); var tab2=document.getElementById("demo2"); $("#demo2").text($("#demo1").clone()); $("#demo2").clone(); function Marquee(){ if(tab2.offsetWidth-tab.scrollLeft<=0) tab.scrollLeft-=tab1.offsetWidth else{ tab.scrollLeft++; } } var MyMar=setInterval(Marquee,speed); tab.onmouseover=function() {clearInterval(MyMar)}; tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)}; </script>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持安科网!
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17