I want to move a serie of images from right to left using javascript.
window.onload = function(){
function move(){
var speed = 500;
var imgbox = document.getElementById("imgbox");
imgbox.innerHTML += imgbox.innerHTML;
var span = imgbox.getElementsByTagName("span");
var timer = window.setInterval(marquee,speed);
function marquee(){
console.log(imgbox.scrollLeft);
console.log(span[0].offsetWidth);
if( imgbox.scrollLeft > span[0].offsetWidth){
imgbox.scrollLeft = 0;
}else{
++imgbox.scrollLeft;
console.log("in else block");
console.log(imgbox.scrollLeft);
}
}
}
move();
}
div{
width: 933px;
height: 129px;
border: 1px solid red;
overflow:hidden;
}
<div id="imgbox">
<span>
<a href=""><img src="https://i.stack.imgur.com/b7J9w.jpg" alt=""></a>
<a href=""><img src="https://i.stack.imgur.com/yh7YJ.jpg" alt=""></a>
<a href=""><img src="https://i.stack.imgur.com/5uIog.jpg" alt=""></a>
<a href=""><img src="https://i.stack.imgur.com/r5GCW.jpg" alt=""></a>
</span>
</div>
When to open it with firefox, js run in else block
,why imgbox.scrollLeft
can't increase?imgbox.scrollLeft
keep value as 0
,not increased as 1
,2
,3
.......
How to fix my js or css ?