I have some problems with the marquee effect using JavaScript. It should stop in the middle when scrolling, but it can't stop in the middle at present, it will shake effect. How can I fix this?
I have solved the problem for a lot of time by myself, so I came up to ask everyone, thank you
function slideLine(box,stf,delay,speed,h)
{
var slideBox = document.getElementById(box);
var delay = delay||1000,speed = speed||20,h = h||20;
var tid = null,pause = false;
var s = function(){tid=setInterval(slide, speed);}
var slide = function(){
if(pause) return;
slideBox.scrollTop += 1;
if(slideBox.scrollTop%h == 0){
clearInterval(tid);
slideBox.appendChild(slideBox.getElementsByTagName(stf)[0]);
slideBox.scrollTop = 0;
setTimeout(s, delay);
}
}
slideBox.onmouseover=function(){pause=true;}
slideBox.onmouseout=function(){pause=false;}
setTimeout(s, delay);
}
slideLine('ann_box','div',2000,25,20);
.ann{
overflow:hidden;
height:60px;
background-color: #ccc;
text-align:center;
}
<div id="ann_box" class="ann" style="width:868px;">
<div id="a1" class="ann">HTML</div>
<div id="a2" class="ann">CSS</div>
<div id="a3" class="ann">Vue</div>
<div id="a4" class="ann">javascript</div>
</div>