Skip to content

Commit 155ee59

Browse files
committed
support Chrome 73+ with passive listeners
1 parent 916f1ad commit 155ee59

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

SmoothScroll.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ function isScrollBehaviorSmooth(el) {
587587
* HELPERS
588588
***********************************************/
589589

590-
function addEvent(type, fn) {
591-
window.addEventListener(type, fn, false);
590+
function addEvent(type, fn, arg) {
591+
window.addEventListener(type, fn, arg || false);
592592
}
593593

594-
function removeEvent(type, fn) {
595-
window.removeEventListener(type, fn, false);
594+
function removeEvent(type, fn, arg) {
595+
window.removeEventListener(type, fn, arg || false);
596596
}
597597

598598
function isNodeName(el, tag) {
@@ -743,14 +743,20 @@ var isIEWin7 = /Windows NT 6.1/i.test(userAgent) && /rv:11/i.test(userAgent);
743743
var isOldSafari = isSafari && (/Version\/8/i.test(userAgent) || /Version\/9/i.test(userAgent));
744744
var isEnabledForBrowser = (isChrome || isSafari || isIEWin7) && !isMobile;
745745

746-
var wheelEvent;
747-
if ('onwheel' in document.createElement('div'))
748-
wheelEvent = 'wheel';
749-
else if ('onmousewheel' in document.createElement('div'))
750-
wheelEvent = 'mousewheel';
746+
var supportsPassive = false;
747+
try {
748+
window.addEventListener("test", null, Object.defineProperty({}, 'passive', {
749+
get: function () {
750+
supportsPassive = true;
751+
}
752+
}));
753+
} catch(e) {}
754+
755+
var wheelOpt = supportsPassive ? { passive: false } : false;
756+
var wheelEvent = 'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel';
751757

752758
if (wheelEvent && isEnabledForBrowser) {
753-
addEvent(wheelEvent, wheel);
759+
addEvent(wheelEvent, wheel, wheelOpt);
754760
addEvent('mousedown', mousedown);
755761
addEvent('load', init);
756762
}

0 commit comments

Comments
 (0)