diff --git a/src/core/grab-cursor/setGrabCursor.js b/src/core/grab-cursor/setGrabCursor.js index 409868a03..cda09461c 100644 --- a/src/core/grab-cursor/setGrabCursor.js +++ b/src/core/grab-cursor/setGrabCursor.js @@ -7,6 +7,14 @@ export default function setGrabCursor(moving) { ) return; const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl; + if (swiper.isElement) { + swiper.__preventObserver__ = true; + } el.style.cursor = 'move'; el.style.cursor = moving ? 'grabbing' : 'grab'; + if (swiper.isElement) { + requestAnimationFrame(() => { + swiper.__preventObserver__ = false; + }); + } } diff --git a/src/core/grab-cursor/unsetGrabCursor.js b/src/core/grab-cursor/unsetGrabCursor.js index 7cefa2fd4..44b121b9f 100644 --- a/src/core/grab-cursor/unsetGrabCursor.js +++ b/src/core/grab-cursor/unsetGrabCursor.js @@ -3,5 +3,13 @@ export default function unsetGrabCursor() { if ((swiper.params.watchOverflow && swiper.isLocked) || swiper.params.cssMode) { return; } + if (swiper.isElement) { + swiper.__preventObserver__ = true; + } swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = ''; + if (swiper.isElement) { + requestAnimationFrame(() => { + swiper.__preventObserver__ = false; + }); + } } diff --git a/src/core/modules/observer/observer.js b/src/core/modules/observer/observer.js index cb2bf30a8..54e3f012f 100644 --- a/src/core/modules/observer/observer.js +++ b/src/core/modules/observer/observer.js @@ -10,10 +10,12 @@ export default function Observer({ swiper, extendParams, on, emit }) { // The observerUpdate event should only be triggered // once despite the number of mutations. Additional // triggers are redundant and are very costly + if (swiper.__preventObserver__) return; if (mutations.length === 1) { emit('observerUpdate', mutations[0]); return; } + const observerUpdate = function observerUpdate() { emit('observerUpdate', mutations[0]); };