Created
February 11, 2015 20:55
-
-
Save aibrean/32fbc7739e819414bfc2 to your computer and use it in GitHub Desktop.
Enable Google map zooming on click only (disable scrolling)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Disable scroll zooming and bind back the click event | |
var onMapMouseleaveHandler = function (event) { | |
var that = $(this); | |
that.on('click', onMapClickHandler); | |
that.off('mouseleave', onMapMouseleaveHandler); | |
that.find('iframe').css("pointer-events", "none"); | |
// pointer-events needs to be added as a style on the iframe | |
} | |
var onMapClickHandler = function (event) { | |
var that = $(this); | |
// Disable the click handler until the user leaves the map area | |
that.off('click', onMapClickHandler); | |
// Enable scrolling zoom | |
that.find('iframe').css("pointer-events", "auto"); | |
// Handle the mouse leave event | |
that.on('mouseleave', onMapMouseleaveHandler); | |
} | |
// Enable map zooming with mouse scroll when the user clicks the map referencing map container | |
$('.google-maps').on('click', onMapClickHandler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment