How to stopPropagation of touch event on overlay GoogleMap

时间:2017-12-18 06:57:50

标签: javascript google-maps

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.

1 个答案:

答案 0 :(得分:1)

您可以为touchend事件添加侦听器,以便停止此事件的传播:

  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/