I need to create a screen saver which has 2 images. One image should be static fixed which should occupy whole screen and second image should be moving on top of first one. I coded as below.
var bdg_img = document.getElementById('bdgimg');
var animate;
function moveRight()
{
bdg_img.style.left = parseInt(bdg_img.style.left) + 10 + 'px';
animate = setTimeout(moveRight,20); // call moveRight in 20msec
}
moveRight();
html, body {
position: relative;
height: 100%;
width: 100%
}
#bgimg {
background-image: url("background/moon_bg.png");
position: absolute;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 100%;
}
#bdgimg {
background-image: url("buildings/bdg6.png");
position: absolute;
background-color:transparent;
bottom: 0px;
left : 0px;
width: 100%;
height: 100%;
border: 1px solid black;
}
<div id="bgimg">
</div>
<div id="bdgimg">
</div>
Even though moveRight() function is getting called continuously, 'bdgimg' div is not moving. Can anyone please let me know how to fix this.