Skip to content

Commit e34f1a3

Browse files
committed
fix(swiper): add passive: false to eventListener to avoid bug when $container is document.body
BUG: when $container is document.body, chrome version higher than 56 will display a warning, since the default value of passive is true on document. see https://www.chromestatus.com/features/5093566007214080 FIX: add {passive: false} to add/removeEventListener, since Typescript’s default signature of `option` in addEventListener is boolean, and in removeEventListener is bool | targetEventOption, add static cast to any to avoid this bug. microsoft/TypeScript#9548 microsoft/TypeScript-DOM-lib-generator#224 TODO: may need remove this cast in later Typescript version
1 parent c0df9cb commit e34f1a3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/swiper.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ export class Swiper {
187187
}
188188

189189
private bindEvents() {
190-
this.$container.addEventListener(Swiper.Device.startEvent, this);
191-
this.$container.addEventListener(Swiper.Device.moveEvent, this);
192-
window.addEventListener(Swiper.Device.endEvent, this);
190+
this.$container.addEventListener(Swiper.Device.startEvent, this, <any>{passive: false});
191+
this.$container.addEventListener(Swiper.Device.moveEvent, this, <any>{passive: false});
192+
window.addEventListener(Swiper.Device.endEvent, this, <any>{passive: false});
193193
window.addEventListener(Swiper.Device.resizeEvent, this, false);
194194
}
195195

196196
private unbindEvents() {
197-
this.$container.removeEventListener(Swiper.Device.startEvent, this);
198-
this.$container.removeEventListener(Swiper.Device.moveEvent, this);
199-
window.removeEventListener(Swiper.Device.endEvent, this);
197+
this.$container.removeEventListener(Swiper.Device.startEvent, this, <any>{passive: false});
198+
this.$container.removeEventListener(Swiper.Device.moveEvent, this, <any>{passive: false});
199+
window.removeEventListener(Swiper.Device.endEvent, this, <any>{passive: false});
200200
window.removeEventListener(Swiper.Device.resizeEvent, this, false);
201201
}
202202

0 commit comments

Comments
 (0)