Skip to content

Fix mouse wheel scroll listenings #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/core/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ export function addDomEvent(obj, typeArr, handler, context) {
callback: eventHandler,
src: handler
});
//firefox
if (type === 'mousewheel' && Browser.gecko) {
type = 'DOMMouseScroll';
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
if (Browser.ie) {
// ie doesn't support options as the third parameter
obj.addEventListener(type, eventHandler, false);
} else {
obj.addEventListener(type, eventHandler, { capture: false, passive: false });
}
obj.addEventListener(type, eventHandler, false);
}
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/map/handler/Map.ScrollWheelZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class MapScrollWheelZoomHandler extends Handler {
}

addHooks() {
addDomEvent(this.target._containerDOM, 'mousewheel', this._onWheelScroll, this);
addDomEvent(this.target._containerDOM, 'wheel', this._onWheelScroll, this);
}

removeHooks() {
removeDomEvent(this.target._containerDOM, 'mousewheel', this._onWheelScroll);
removeDomEvent(this.target._containerDOM, 'wheel', this._onWheelScroll);
}

_onWheelScroll(evt) {
Expand Down Expand Up @@ -128,7 +128,7 @@ class MapScrollWheelZoomHandler extends Handler {
return false;
}
this._requesting = 0;
let levelValue = (evt.wheelDelta ? evt.wheelDelta : evt.detail) > 0 ? 1 : -1;
let levelValue = (evt.deltaY ? evt.deltaY * -1 : evt.wheelDelta ? evt.wheelDelta : evt.detail) > 0 ? 1 : -1;
if (evt.detail) {
levelValue *= -1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/map/MapAnimSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('Map.Anim', function () {
});
setTimeout(function () {
happen.once(container, {
type: (maptalks.Browser.gecko ? 'DOMMouseScroll' : 'mousewheel'),
type: 'wheel',
detail: 100
});
}, 100);
Expand Down
2 changes: 1 addition & 1 deletion test/map/MapScrollZoomSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Map.ScrollZoom', function () {
var delay;
function scrollMap(delta) {
happen.once(container, {
type: (maptalks.Browser.gecko ? 'DOMMouseScroll' : 'mousewheel'),
type: 'wheel',
detail: delta
});
}
Expand Down