For my project I want a parallax scrolling effect only if the screen size is equal or wider than 800px. To do this I wrote following code:
<script>
if (window.screen.width >= 800) {
function parallax() {
var parallax = document.getElementById("box01");
parallax.style.top = -(window.pageYOffset / 4) + "px";
}
}
window.addEventListener("scroll", parallax, false);
</script>
The parallax scrolling works fine but the "window.screen.width" command is ignored by the browser. Means: The parallax scrolling is also enabled for screen smaller than 800px.
Any help is appreciated!