Skip to content

Instantly share code, notes, and snippets.

@tomlokhorst
Created December 18, 2014 09:01
Show Gist options
  • Save tomlokhorst/413457d8956d01638993 to your computer and use it in GitHub Desktop.
Save tomlokhorst/413457d8956d01638993 to your computer and use it in GitHub Desktop.
Don't zoom in on Google Maps when scrolling through a website
function fixMapScrollwheel(map) {
map.setOptions({ scrollwheel: false });
google.maps.event.addListener(map, 'click', function() {
map.setOptions({ scrollwheel: true });
});
google.maps.event.addListener(map, 'mouseout', function() {
map.setOptions({ scrollwheel: false });
});
}
@guidobouman
Copy link

You could catch accidental map leaves:

  google.maps.event.addListener(map, 'mouseout', function() {
    var timeout = setTimeout(function() {
      map.setOptions({ scrollwheel: false });
      google.maps.event.removeListener(map, 'mouseenter');
    }.bind(this), 750);

    google.maps.event.addListener(map, 'mouseenter', function() { clearTimeout(timeout) });
  });

(Written from the top of my head. Not tested.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment