Skip to content

Instantly share code, notes, and snippets.

@miceno
Created August 29, 2015 11:14
Show Gist options
  • Save miceno/c6c9087d88e10a5a2da5 to your computer and use it in GitHub Desktop.
Save miceno/c6c9087d88e10a5a2da5 to your computer and use it in GitHub Desktop.
Disable scroll wheel zoom on Google Maps iframes.
.google-maps-responsive {
position: relative;
padding-bottom: 75%; // This is the aspect ratio
height: 0;
overflow: hidden;
}
.google-maps-responsive iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/*
Thanks to http://stackoverflow.com/a/25904582/165407
*/
jQuery(document).ready(function($){
// 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");
}
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
$('.google-maps-responsive').on('click', onMapClickHandler);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment