E
E
enginel2021-06-21 10:56:34
JavaScript
enginel, 2021-06-21 10:56:34

How to disable the function on resize?

Can you please tell me how to disable the function at a small resolution, and execute the function ONCE at a large one? That is, if the resolution changed, the function would no longer run again

window.addEventListener("resize", function() {
if (window.innerWidth < 1024) {
console.log('mobile');

???

}
if (window. innerWidth >= 1024) {
console.log('note');
myFunction();
}
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xirurgx3d, 2021-06-21
@enginel

use window.removeEventListener("resize", func)
but first move the function in window.addEventListener("resize", func) to the top and name it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question