mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
28 lines
676 B
JavaScript
28 lines
676 B
JavaScript
// eslint-disable-next-line import/no-mutable-exports
|
|
export let supportsPassive = false;
|
|
|
|
try {
|
|
const opts = {};
|
|
Object.defineProperty(opts, 'passive', {
|
|
// eslint-disable-next-line getter-return
|
|
get() {
|
|
/* istanbul ignore next */
|
|
supportsPassive = true;
|
|
},
|
|
});
|
|
window.addEventListener('test-passive', null, opts);
|
|
// eslint-disable-next-line no-empty
|
|
} catch (e) {}
|
|
|
|
export function on(target, event, handler, passive = false) {
|
|
target.addEventListener(
|
|
event,
|
|
handler,
|
|
supportsPassive ? { capture: false, passive } : false
|
|
);
|
|
}
|
|
|
|
export function off(target, event, handler) {
|
|
target.removeEventListener(event, handler);
|
|
}
|