Home > Web Front-end > JS Tutorial > body text

Marquee-like horizontal circular scrolling implemented in js_javascript skills

WBOY
Release: 2016-05-16 18:31:53
Original
985 people have browsed it
Copy code The code is as follows:

<script> <br>var speed=20;/*speed The larger the value, the slower the speed*/ <br>document.getElementById('www_qpsh_com2').innerHTML=document.getElementById('www_qpsh_com1').innerHTML; <br><br>/*The two layers alternate back and forth*/ <br>function Marquee(){ <br>if(document.getElementById('www_qpsh_com2').offsetWidth-document.getElementById('www_qpsh_com').scrollLeft<=0) <BR>document.getElementById('www_qpsh_com').scrollLeft -=document.getElementById('www_qpsh_com1').offsetWidth; <BR>else{ <BR>document.getElementById('www_qpsh_com').scrollLeft ; <BR>} <BR>document.getElementById('my_marquee_info').innerHTML= ''; <BR>document.getElementById('my_marquee_info').innerHTML ='div.scrollTop:' document.getElementById('www_qpsh_com').scrollLeft; <BR>} <BR>var MyMar=setInterval(Marquee,speed) ; <BR>www_qpsh_com.onmouseover=function() {clearInterval(MyMar);} <BR>www_qpsh_com.onmouseout=function() {MyMar=setInterval(Marquee,speed);} <BR></script>

Demo code:

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> var speed=20;/*速度数值越大速度越慢*/ document.getElementById('www_qpsh_com2').innerHTML=document.getElementById('www_qpsh_com1').innerHTML; function Marquee(){ if(document.getElementById('www_qpsh_com2').offsetWidth-document.getElementById('www_qpsh_com').scrollLeft<=0) document.getElementById('www_qpsh_com').scrollLeft-=document.getElementById('www_qpsh_com1').offsetWidth; else{ document.getElementById('www_qpsh_com').scrollLeft++; } document.getElementById('my_marquee_info').innerHTML=''; document.getElementById('my_marquee_info').innerHTML+='div.scrollTop:'+document.getElementById('www_qpsh_com').scrollLeft; } var MyMar=setInterval(Marquee,speed); www_qpsh_com.onmouseover=function() {clearInterval(MyMar);} www_qpsh_com.onmouseout=function() {MyMar=setInterval(Marquee,speed);} </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!