0

I have a parallax effect written in JavaScript. This effect swings the picture from side to side. I want to disable it for tablets and mobile devices. My JavaScript code for parallax.

let bg = document.querySelector('.main__bg');
window.addEventListener('mousemove', function(e) {
    let x = e.clientX / window.innerWidth;
    let y = e.clientY / window.innerHeight;  
    bg.style.transform = 'translate(-' + x * 50 + 'px, -' + y * 50 + 'px)';
  });

I tried to add this code, but it doesn't work. How can the problem be solved?

if ($(window).width() > 1024) { 

let bg = document.querySelector('.main__bg');
window.addEventListener('mousemove', function(e) {
    let x = e.clientX / window.innerWidth;
    let y = e.clientY / window.innerHeight;  
    bg.style.transform = 'translate(-' + x * 50 + 'px, -' + y * 50 + 'px)';
  });
}

0 Answers0