Created
October 15, 2014 13:16
-
-
Save patrykgruszka/fea907be99b02f7f100f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var el = $('#map'); | |
var map; | |
function enableScrollingWithMouseWheel() { | |
map.setOptions({ | |
scrollwheel: true | |
}); | |
} | |
function disableScrollingWithMouseWheel() { | |
map.setOptions({ | |
scrollwheel: false | |
}); | |
} | |
function init() { | |
map = new google.maps.Map(el[0], { | |
zoom: 10, | |
center: new google.maps.LatLng(47.49840560, 19.04075779), | |
scrollwheel: false // disableScrollingWithMouseWheel as default | |
}); | |
google.maps.event.addListener(map, 'mousedown', function() { | |
enableScrollingWithMouseWheel() | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', init); | |
$('body').on('mousedown', function(event) { | |
var clickedInsideMap = $(event.target).parents('#map').length > 0; | |
if (!clickedInsideMap) { | |
disableScrollingWithMouseWheel(); | |
} | |
}); | |
$(window).scroll(function() { | |
disableScrollingWithMouseWheel(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment