Javascript 单击iframe嵌入映射时启用指针事件

Javascript 单击iframe嵌入映射时启用指针事件,javascript,jquery,css,google-maps,iframe,Javascript,Jquery,Css,Google Maps,Iframe,我有一个iframe标签中的地图,工作非常好。我想要的是当点击框架时,指针事件再次启用并交互(缩放、点击标记等) 指针事件有效,我无法与地图交互。 我想要的是,当单击映射时,指针事件变为“自动” 我已经尝试了javascript的这段代码,但什么也没发生。有什么想法吗 <script> $(document).ready(function() { $('#map').css('pointer-events', 'none'); $('#map').cl

我有一个iframe标签中的地图,工作非常好。我想要的是当点击框架时,指针事件再次启用并交互(缩放、点击标记等)

指针事件有效,我无法与地图交互。 我想要的是,当单击映射时,指针事件变为“自动”

我已经尝试了javascript的这段代码,但什么也没发生。有什么想法吗

<script>
   $(document).ready(function() {
      $('#map').css('pointer-events', 'none');

      $('#map').click(function() {
        $(this).css('pointer-events', 'auto');
      });
   });
</script>

$(文档).ready(函数(){
$('#map').css('pointer-events','none');
$(“#映射”)。单击(函数(){
$(this.css('pointer-events','auto');
});
});

提前感谢

您无法获取具有“指针事件:无”的元素的单击事件。您应该做的是将其添加到div中

比如说,

<div class="map-wrapper"><iframe id="map"></iframe></div>

然后,将脚本称为

    <script>
       $(document).ready(function() {
          $('#map').css('pointer-events', 'none');
          $('.map-wrapper').click(function() {
            $(this).find('#map').css('pointer-events', 'auto'); // just $('#map') also fine
          });
          $('.map-wrapper').mouseleave(function() {
            $(this).find('#map').css('pointer-events', 'none'); // making it not clickable when it's not in focus
          });

       });
    </script>

$(文档).ready(函数(){
$('#map').css('pointer-events','none');
$('.map wrapper')。单击(函数(){
$(this).find('#map').css('pointer-events','auto');//只要$('#map')也可以
});
$('.map wrapper').mouseleave(函数(){
$(this).find(“#map”).css('pointer-events','none');//使其在不处于焦点时不可单击
});
});

希望这有帮助

谢谢,这很有帮助!最后,我将
.click
事件更改为
.mouseenter
事件,然后根据该元素的
onmousedown
事件存储了一个变量,表示我是否与iframe外部的另一个元素交互。在
.mouseenter
函数中,我说如果iframe之外没有交互,那么执行。这可以让你在iframe中拖动,而不必先单击。哇,现在我想起来了,我可以使用
.onmousedown
。我真傻!现在太晚了,改变它是没有意义的。
<div class="map-wrapper"><iframe id="map"></iframe></div>
    <script>
       $(document).ready(function() {
          $('#map').css('pointer-events', 'none');
          $('.map-wrapper').click(function() {
            $(this).find('#map').css('pointer-events', 'auto'); // just $('#map') also fine
          });
          $('.map-wrapper').mouseleave(function() {
            $(this).find('#map').css('pointer-events', 'none'); // making it not clickable when it's not in focus
          });

       });
    </script>