Prevent a Google Maps iframe from capturing the mo

2019-01-21 05:02发布

This question already has an answer here:

If you're browsing with an embedded maps iframe using your trackpad or mouse, you can potentially trap yourself into the Maps' zooming capabilities, which is really annoying.

Try it here: https://developers.google.com/maps/documentation/embed/guide#overview

Is there a way to prevent this?

9条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-21 05:27

Taken from

How to disable mouse scroll wheel scaling with Google Maps API

You can just disable the scroll wheel functionality

options = $.extend({ scrollwheel: false, navigationControl: false, mapTypeControl: false, scaleControl: false, draggable: false, mapTypeId: google.maps.MapTypeId.ROADMAP }, options);

查看更多
你好瞎i
3楼-- · 2019-01-21 05:29

Is it possible to disable mouse scroll wheel zoom on embedded Google Maps?

Here is preety good answer. In my case it need to be fixed with jquery to work perfect. My code is:

HTML

<div class="overlay"></div>
<iframe src="#MAP_LINK#" width="1220" height="700" frameborder="0" style="border:0; margin-top: 20px;" ></iframe>

CSS

.overlay {
background:transparent; 
position:relative; 
width:1220px;
height:720px; /* your iframe height */
top:720px;  /* your iframe height */
margin-top:-720px;  /* your iframe height */
}

JQUERY

$('.overlay').click(function(){
$(this).removeClass('overlay');
});
查看更多
放荡不羁爱自由
4楼-- · 2019-01-21 05:30

I had many maps within my website so I modified @Ronaldinho Learn Coding answer to a more general one.

$( document ).ready(function() {
   $('.scroll-safe-map').addClass('scrolloff'); 
   $('.map-control-scroll').on('click', function() {
       $('.scroll-safe-map').removeClass('scrolloff');
   });
   $('.map-control-scroll').mouseleave(function() {
       $('.scroll-safe-map').addClass('scrolloff'); 
   });    
});
查看更多
登录 后发表回答