我在Google我的地图(自定义地图)的iframe上禁用滚动浏览时遇到问题。由于它也具有可点击的事件,因此我不能使用CSS“ pointer-events:none”。我也在iframe本身上尝试了“ scrolling:no”,但是这两种方法都不起作用。我终于使用了JavaScript作为。
<script>
$(".map").bind("mousewheel", function() {
return false;
});
</script>
它有效,但是当我单击其中一个链接时,它又开始滚动。如何明确禁用滚动,但仍使用clickable事件。
答案 0 :(得分:0)
一个工作示例:
<!DOCTYPE html>
<html>
<head>
<style>
.scrolloff {
pointer-events: none;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#map').addClass('scrolloff'); // set the mouse events to none when doc is ready
$('#overlay').on("mouseup",function(){ // lock it when mouse up
$('#map').addClass('scrolloff');
//somehow the mouseup event doesn't get call...
});
$('#overlay').on("mousedown",function(){ // when mouse down, set the mouse events free
$('#map').removeClass('scrolloff');
});
$("#map").mouseleave(function () { // becuase the mouse up doesn't work...
$('#map').addClass('scrolloff'); // set the pointer events to none when mouse leaves the map area
// or you can do it on some other event
});
});
</script>
</head>
<body>
<div id="overlay" class="map">
<iframe id="map" src="https://www.google.com/maps/embed/v1/place?key=AIzaSyCjUE83FHrXTQWf9umcNDzyu0s7aNzHszw
&q=Space+Needle,Seattle+WA" width="100%" height="500" frameborder="0" ></iframe>
</div>
</body>
</html>