Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a map that I wish to integrate into a page. When I simply scroll over it, the map won't zoom and I can view the next content. But when I ctrl + scroll over the map, it will zoom in.
How can I do that with mapbox?
Try this (no jquery required):
map.on("wheel", event => { if (event.originalEvent.ctrlKey) { return; } if (event.originalEvent.metaKey) { return; } if (event.originalEvent.altKey) { return; } event.preventDefault(); });
see https://github.com/mapbox/mapbox-gl-js/issues/6884
Add a comment
Try this, where map is your map variable. Also, you can bind this event on some div, I think, not the whole window.
$(window).bind('mousewheel DOMMouseScroll', function(event) { if(event.ctrlKey == true) { map['scrollZoom'].enable(); } else { map['scrollZoom'].disable(); } });
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.