css 阻止鼠标滚动到Google地图上

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 阻止鼠标滚动到Google地图上相关的知识,希望对你有一定的参考价值。

<div class="iframe-container">
    <iframe class="actAsDiv" id="myiFrame" src="https://a.tiles.mapbox.com/v4/rvno12.ped3hmmm/attribution,zoompan,zoomwheel,geocoder,share.html?access_token=pk.eyJ1IjoicnZubzEyIiwiYSI6InVVbXhUam8ifQ.vYxp4PFKqTHJCvnnqqMybg" style="border:0px #FFFFFF none;" name="myiFrame" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="500px" width="100%" seamless></iframe>
</div>
// Prevent mouse scroll over Google maps iframe
$(document).ready(function () {
    // you want to enable the pointer events only on click;

    $('#myiFrame').addClass('scrolloff'); // set the pointer events to none on doc ready
    $('.iframe-container').on('click', function () {
        $('#myiFrame').removeClass('scrolloff'); // set the pointer events true on click
    });

    // you want to disable pointer events when the mouse leave the canvas area;

    $("#myiFrame").mouseleave(function () {
        $('#myiFrame').addClass('scrolloff'); // set the pointer events to none when mouse leaves the map area
    });
});
.scrolloff {
  pointer-events: none;
}

以上是关于css 阻止鼠标滚动到Google地图上的主要内容,如果未能解决你的问题,请参考以下文章

显示信息窗口后阻止谷歌地图移动

高德地图禁止鼠标滚动事件

在信息窗口中使用 Google Maps v3 禁用鼠标滚轮缩放

javascript 阻止Google地图在移动设备上拖动

Openlayers的Overlay里面不支持移动端滚动事件

在嵌入式 Google 地图上禁用鼠标滚轮缩放