Home >Web Front-end >JS Tutorial >js practical non-stop scrolling effect (good compatibility)_image special effects
js practical non-stop scrolling effect (good compatibility)_image special effects
WBOYOriginal
2016-05-16 18:25:281263browse
Here is a method; basically, the structure and behavior are separated. The connection between the two only requires one id. It is very convenient to use, and the same js code can achieve multiple scrolling chart effects on this page. Without interfering with each other, 1.xhtml
function startmarquee(lh,speed,delay,index){ var o =document.getElementById("demo" index); var o_td=o.getElementsByTagName("td")[0]; var str=o_td.innerHTML; var newtd=document.createElement(" td"); newtd.innerHTML=str; o_td.parentNode.appendChild(newtd); var t; var p=false; o.onmouseover=function(){ p=true;} o.onmouseout=function() {p=false;} function start(){ t=setInterval(Marquee,speed); if(!p){ o.scrollLeft = 3;} } function Marquee(){ if(o_td.offsetWidth-o.scrollLeft<=0) o.scrollLeft-=o_td.offsetWidth; else{ if(o.scrollLeft%lh!=0){ o.scrollLeft = 3 }else{clearInterval(t); setTimeout(start,delay);} } } setTimeout(start,delay); } startmarquee(102,1,1500,1);//Stop scrolling between pictures startmarquee(102,30,1,2) ;//Uninterrupted scrolling of images
Test code: js needs to be executed after the html file is loaded to run normally, so remember to put js after the div; the principle of image scrolling and text scrolling Much the same. Demo code:
] In the code, it is for 102 The width of the picture can be modified in the code. Only the width that suits your picture size can run perfectly.
Statement:
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