0

I am using a Mac Trackpad on a Google Map. If I two-finger swipe down or up, the map zooms in or out (like it should), but then the entire page scrolls up or down.

I think it has to do with the Trackpad momentum (probably the same on a Magic Mouse).

When I use a normal mouse with a scroll wheel, I don't have the same problem.

I have tried doing things like e.preventDefault() in the scroll listener of the map element, but no luck.

To see an example, just zoom in or out really fast on Google's own demo page: https://developers.google.com/maps/documentation/javascript/examples/map-simple

How do I prevent the entire page from scrolling when I am only trying to zoom the map?

Thank you!

Richard Slater
  • 6,313
  • 4
  • 53
  • 81
Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106

2 Answers2

2

With jQuery try this:

 $("#idOfMap").on("wheel mousewheel DOMMouseScroll", function(e){
     e.preventDefault();
 });

When using jQuery prior 1.7 use bind() instead of on().

timbernasley
  • 490
  • 9
  • 21
0

Worked fine for me, try downloading MagicPrefs for your trackpad, it gives you much greater preferences regarding the way your trackpad works. http://magicprefs.com/

Joe Perkins
  • 261
  • 3
  • 9
  • 17