I'm using Framework7 sortable list and it works well, just that it doesn't trigger an event when the list is changed.
So I'm trying a few built-in events:
$('.sortable-handler').on('touchstart', function (e) {
e.preventDefault();
alert('touchstart');
});
$('.sortable-handler').on('touchmove', function (e) {
e.preventDefault();
console.log('touchmove');
});
$('.sortable-handler').on('touchcancel', function (e) {
e.preventDefault();
console.log('touchcancel');
});
$('.sortable-handler').mouseleave(function (e) {
e.preventDefault();
console.log('mouseleave');
});
.. but all I get is:
Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080
Which event should I look for to get the updated list on every sort?
Remove the need for preventDefault() in the event listener The correct way to fix this issue is by finding the event listener responsible for generating the intervention violation and removing the preventDefault() call in that event listener. The preventDefault() call can't be used in a passive event listener.
Passive event listeners are an emerging web standard, new feature shipped in Chrome 51 that provide a major potential boost to scroll performance. Chrome Release Notes. It enables developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners.
Remove the need for preventDefault () in the event listener The correct way to fix this issue is by finding the event listener responsible for generating the intervention violation and removing the preventDefault () call in that event listener. The preventDefault () call can't be used in a passive event listener.
Since Chrome 56, all touch event listeners are passive by default. Check this in-depth video if you want to learn more about passive event listeners and scrolling smoothness. There are two ways to solve this violation. We recommend the first option. 1. Remove the need for preventDefault () in the event listener
Developer-defined “passive event listeners” solve this. When you add a touch event with a {passive: true} object as the third parameter in your event handler then you are telling the browser that the touchstart listener will not call preventDefault () and the browser can safely perform the scroll without blocking on the listener.
This violation is about the javascript Event Listeners. Since Chrome 51, an event listener can be set as "passive". Passive event listeners were introduced to optimize scrolling performance on a device. When you use a passive event listener on your site, you promise not to use a preventDefault () in that listener to disable scrolling.
See this blog post. If you call preventDefault
on every touchstart
then you should also have a CSS rule to disable touch scrolling like
.sortable-handler {
touch-action: none;
}
For me
document.addEventListener("mousewheel", this.mousewheel.bind(this), { passive: false });
did the trick (the { passive: false }
part).
In plain JS add { passive: false }
as third argument
document.addEventListener('wheel', function(e) {
e.preventDefault();
doStuff(e);
}, { passive: false });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With