mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 02:31:21 +00:00
perf: remove passive event polyfill (#9590)
This commit is contained in:
@@ -135,35 +135,12 @@ function throttle(action, delay) {
|
||||
};
|
||||
}
|
||||
|
||||
function testSupportsPassive() {
|
||||
if (!inBrowser) return;
|
||||
let support = false;
|
||||
try {
|
||||
const opts = Object.defineProperty({}, 'passive', {
|
||||
// eslint-disable-next-line getter-return
|
||||
get() {
|
||||
support = true;
|
||||
},
|
||||
});
|
||||
window.addEventListener('test', null, opts);
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
const supportsPassive = testSupportsPassive();
|
||||
|
||||
const _ = {
|
||||
on(el, type, func, capture = false) {
|
||||
if (supportsPassive) {
|
||||
el.addEventListener(type, func, {
|
||||
capture,
|
||||
passive: true,
|
||||
});
|
||||
} else {
|
||||
el.addEventListener(type, func, capture);
|
||||
}
|
||||
el.addEventListener(type, func, {
|
||||
capture,
|
||||
passive: true,
|
||||
});
|
||||
},
|
||||
off(el, type, func, capture = false) {
|
||||
el.removeEventListener(type, func, capture);
|
||||
|
Reference in New Issue
Block a user