jQuery ContextMenu事件在IOS 8.2中不起作用
jQuery ContextMenu event not working in IOS 8.2
我在.html示例中使用contextMenu事件,当我长按div时,它会被触发,但现在它不起作用。在最新的IOS 8.2版本中出现了问题。这是示例代码,
<head>
<title></title>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#content").on("contextmenu", function () {
alert("CM");
});
});
</script>
</head>
<body>
<div id="content" style="height:300px; width:300px; background-color:gray;"></div>
</body>
这是的工作样本
http://jsfiddle.net/4zu1ckgg/
请有人帮我做这件事。
基本上,在iOS上,触摸事件不会模拟为鼠标事件。使用触摸事件:"触摸开始"、"触摸移动"answers"触摸结束"。
在您的情况下,在iOS上,与Android相反,长时间触摸屏幕时不会触发"上下文菜单"。要在iOS上自定义长触摸,您应该使用以下内容:
// Timer for long touch detection
var timerLongTouch;
// Long touch flag for preventing "normal touch event" trigger when long touch ends
var longTouch = false;
$(touchableElement)
.on("touchstart", function(event){
// Prevent default behavior
event.preventDefault();
// Test that the touch is correctly detected
alert("touchstart event");
// Timer for long touch detection
timerLongTouch = setTimeout(function() {
// Flag for preventing "normal touch event" trigger when touch ends.
longTouch = true;
// Test long touch detection (remove previous alert to test it correctly)
alert("long mousedown");
}, 1000);
})
.on("touchmove", function(event){
// Prevent default behavior
event.preventDefault();
// If timerLongTouch is still running, then this is not a long touch
// (there is a move) so stop the timer
clearTimeout(timerLongTouch);
if(longTouch){
longTouch = false;
// Do here stuff linked to longTouch move
} else {
// Do here stuff linked to "normal" touch move
}
})
.on("touchend", function(){
// Prevent default behavior
event.preventDefault();
// If timerLongTouch is still running, then this is not a long touch
// so stop the timer
clearTimeout(timerLongTouch);
if(longTouch){
longTouch = false;
// Do here stuff linked to long touch end
// (if different from stuff done on long touch detection)
} else {
// Do here stuff linked to "normal" touch move
}
});
以下是一个页面,解释(除其他外)触摸事件不会在每个操作系统上模拟为鼠标事件:http://www.html5rocks.com/en/mobile/touchandmouse/
希望这能有所帮助,我花了很长时间才弄清楚;)
相关文章:
- jQuery ContextMenu事件在IOS 8.2中不起作用
- Javascript touchend(滚动)事件在ios 4中的UIWebView中不起作用
- Ajax 调用在 IOS 中的用户交互之前不起作用
- window.open()在使用phone gap的iOS应用程序上不起作用
- Skrollr在IOS中不起作用,尽管i'We用Skrollr body包裹身体
- 删除类在 iOS 上不起作用
- Cordova iframe在iOS Safari中工作,但在Android中不起作用
- IOS Cordova/Phonegap 离线视频源标签不起作用
- <表单目标=“_blank”>在 iOS 7.0.3 中不起作用
- Jquery 函数在 ios 设备上不起作用
- 在 iFrame 中滚动事件侦听器在 iOS 上不起作用
- Vimeo 播放器 JS API 在 iOS 中不起作用
- 清除键盘打开时在iOS / iPad中不起作用的所有文本图标
- HTML
- 基于宽度计算的表格列显示和隐藏在 Safari IOS 设备中不起作用
- stringByEvaluatingJavaScriptFromString 在 iOS 7 中不起作用
- Ios webview调用javascript函数将不起作用
- 使用 ATTR 在 iOS 5 上不起作用更改 IMG 源
- Cordova iOS Javascript不起作用
- window.scroll到在iOS chrome中不起作用