Skip to content

Instantly share code, notes, and snippets.

@aktaumag
Created July 9, 2024 20:40
Show Gist options
  • Save aktaumag/2c498a7dc63f4e17c28aac796a60ee31 to your computer and use it in GitHub Desktop.
Save aktaumag/2c498a7dc63f4e17c28aac796a60ee31 to your computer and use it in GitHub Desktop.
jquery Added non-passive event listener to a scroll-blocking
Пасивные события прокрутки в Jquery
@aktaumag
Copy link
Author

aktaumag commented Jul 9, 2024

https://stackoverflow.com/questions/46094912/added-non-passive-event-listener-to-a-scroll-blocking-touchstart-event
После высех jquery файлов или в конец самого последнего, добавляем этот код:

const preventPassiveWarning = event => {
	jQuery.event.special[event] = {
		setup: function (_, ns, handle) {
			if (ns.includes("noPreventDefault")) {
				this.addEventListener(event, handle, { passive: false });
			} else {
				this.addEventListener(event, handle, { passive: true });
			}
		}
	}
}
['touchstart', 'touchmove', 'mousewheel', 'wheel'].forEach(event => preventPassiveWarning(event));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment