I am working on a WordPress site where the authors usually embed Google Maps using iFrames in most posts.
Is there a way to disable the zoom via mouse scroll wheel on all of them using Javascript?
I am working on a WordPress site where the authors usually embed Google Maps using iFrames in most posts.
Is there a way to disable the zoom via mouse scroll wheel on all of them using Javascript?
Using answer from @nathanielperales i've added hover function cause for me it works better when user loses focus on map to stop scrolling again :)
I extended @nathanielperales solution.
Below the behavior description:
Below the javascript code:
And here is an jsFiddle example.
This is a solution with CSS and Javascript (ie. Jquery but works also with pure Javascript). At the same time the map is responsive. Avoid map to zoom when scrolling, but map can be activated by click in it.
HTML/JQuery Javascript
CSS
Have fun !
if you have an iframe using Google map embedded API like this :
you can add this css style: pointer-event:none; ES.
I tried the first answer in this discussion and it wasn't working for me no matter what I did so I came up with my own solution:
Wrap the iframe with a class (.maps in this example) and ideally embedresponsively code: http://embedresponsively.com/ — Change the CSS of the iframe to
pointer-events: none
and then using jQuery's click function to the parent element you can change the iframes css topointer-events:auto
HTML
CSS
jQuery
I'm sure there's a JavaScript only way of doing this, if someone wants to add to this feel free.
The JavaScript way to reactivate the pointer-events is pretty simple. Just give an Id to the iFrame (i.e. "iframe"), then apply an onclick event to the cointainer div:
This is my approach. I find it easy to implement on various websites and use it all the time
CSS and JavaScript:
In the HTML, you will want to wrap the iframe in a div.
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
Hope this helps anyone looking for a simple solution.