【发布时间】:2015-12-07 00:43:35
【问题描述】:
我有一个地图按钮,您可以单击(或点击)显示带有嵌入式 Google 地图的模式。它的工作方式与在不同浏览器的桌面上应有的一样,但在 iPhone(可能还有其他触摸屏)上,我必须点按两次按钮。
编辑:尝试使用“ontouchend”触发,使用“touchend”关闭模式。现在模式一打开就关闭。
HTML:
<div class="map-modal" id="map-modal">
<div class="map-container">
<div class="the-map" id="map-canvas"></div>
<div class="hide-btn hide-btn--map" onclick="closeModal();"><span class="close hairline"></span><div class="hidden-content">Hide the map</div></div>
</div>
</div>
按钮:
<div class="button button--map" onmousedown="calcRoute('<?php echo $location[address1]; ?>', '<?php echo $location[address2]; ?>');">Map</div>
JavaScript:
function calcRoute(start, end) {
var e = document.getElementById("map-modal");
e.style.display = 'block';
$("body").addClass("modal-open");
google.maps.event.trigger(map, 'resize');
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Sorry, no walking route can be found between these locations");
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
【问题讨论】:
-
iPhone 的“onmousedown”相当于“ontouchstart”。 stackoverflow.com/questions/21009821/…
-
奇怪。 ontouchstart 似乎工作“太好了”。它会触发双击,因此模式会在打开后立即关闭,或者,如果谷歌地图徽标恰好与按钮显示在同一位置,则谷歌地图应用程序会打开。
标签: javascript iphone touchscreen