I have made a background with two images inside two divs next to each other that move across the screen using javascript. I made it originally to work with the divs being 2000px wide and thus the second div positioned 2000px left. I have now made an @media feature so it works with screen sizes.
The stylesheet is loading the @media properly, I have tested it by applying borders to it to show it works on the screen size. The Javascript is working, I have tested that. But the left position of it in the css doesn't change where the second div starts and there is always a gap.
This is part of the css:
@media (min-device-width: 800px) and (max-device-width: 1099px) {
#rotsky {position: fixed; bottom: 0px; width: 1400px; background: url('images/skybkm.jpg') no-repeat left bottom}
#rotsky2 {position: fixed; left: 1400px; bottom: 0px; width: 1400px; background: url('images/skybk2m.jpg') no-repeat left bottom}
}
#rotsky {left: 0px; height: 100%; z-index: -2}
#rotsky2 {height: 100%; z-index: -2}
and this is the JS
function applywidth() {
var screenwidth = getWidth();
if (screenwidth <= "799") {
skywidth = "1000";
} else if (screenwidth >= "800" && screenwidth <= "1099") {
skywidth = "1400";
} else if (screenwidth >= "1100") {
skywidth = "2000";
}
}
function rotate() {
newleft-=1.1;
nawleft-=1.1;
if (nawleft <= (0-skywidth)) {
nawleft = skywidth;
}
if (newleft <= (0-skywidth)) {
newleft = skywidth;
}
var nowleft = newleft + "px";
var nuwleft = nawleft + "px";
document.getElementById('rotsky').style.left=nowleft;
document.getElementById('rotsky2').style.left=nuwleft;
}
The rest can be seen on