如何停止覆盖GoogleMap上的触摸事件传播 [英] How to stopPropagation of touch event on overlay GoogleMap

查看:153
本文介绍了如何停止覆盖GoogleMap上的触摸事件传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在这里找到代码 。我尝试过与全球&本地事件

You can find out code here. I tried with global & local event both

event.preventDefault()
event.stopPropagation()
event.returnValue = false
event.cancelBubble = true;

以上代码适用于鼠标点击事件,但触摸事件地图仍然会收到点击事件。

above code working fine for mouse click events but for touch event map still receives click events.

推荐答案

您可以将侦听器添加到 touchend 事件中,停止此事件的传播:

You can add a listener to touchend event, so you can stop the propagation of this event:

  google.maps.event.addDomListener(div, "click", function(e) {
      console.log("over click");
      e.preventDefault();
      e.stopPropagation();
      clickOverlay();
  })

  google.maps.event.addDomListener(div, "touchend", function(e) {
      console.log("over touchend");
      e.preventDefault();
      e.stopPropagation();
      clickOverlay();
  })

这是你的小提琴更新: https://jsfiddle.net/beaver71/xx1ycd7L/

Here is your fiddle updated: https://jsfiddle.net/beaver71/xx1ycd7L/

这篇关于如何停止覆盖GoogleMap上的触摸事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆