1

I have an event listener that is currently being triggered on mousemove. However i want this to only be applied to desktop and not mobile.

And vice versa, for my own reference how would I apply it to mobile only if I wanted to?

Here is my function wrapped around an if statement that if the innerWidth is more than 1000, to trigger add the event listener on mousemove. however I still see it being applied to mobile.

    if (window.innerWidth > 1000) {
    document.addEventListener("mousemove", debounce(inactiveUser, 10000));
    }

If it's helpful, I am triggering an action event being sent to a tool we use for analytics and campaigns called Evergage. The function is below, along with a console log that I added:

    const inactiveUser = () => {
        console.log("mouse move on desktop only");
        sendEvent({
            action: "Inactive Checkout",
        });
    };
1
  • 1
    Invert your strategy. The event handler runs for all screen sizes, but you only take action inside it for larger screens. Commented Dec 5, 2022 at 15:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.