触摸事件在模式弹出窗口上不起作用
Touch events are not working on Modal Popup
我在模态弹出窗口的触摸事件中遇到了一个简单而复杂的问题。在我的弹出窗口中,我显示了一张图像,对于该图像,我正在触发触摸事件,但它在一段时间内有效,并且几乎在所有时间都不起作用。第二个问题仅在模态弹出窗口上:滑动事件根本没有触发。可能有什么问题?以下是我在 Logcat 中收到的警告:对于模态弹出窗口的每一次触摸,我都会得到这个W/webview(5558):从 webcore 接收ACTION_DOWN过时的触摸事件;忽略
对于在模态弹出窗口上滑动,我得到:11-14 12:42:09.420:W/webview(5558):错过了一个拖拽,因为我们正在等待WebCore的响应。
有趣的是,仅在模态弹出窗口上发生,而不是所有屏幕。任何帮助将不胜感激
下面我用于模态弹出窗口的javascript代码
var modal = (function() {
var method = {}, $overlay, $modal, $content, $close;
// Center the modal in the viewport
method.center = function() {
var top, left, position;
top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
$modal.css({
top : top + $(window).scrollTop(),
left : left + $(window).scrollLeft()
});
};
// Open the modal
method.open = function(settings) {
$content.empty().append(settings.content);
$modal.css({
width : settings.width || 'auto',
height : settings.height || 'auto'
});
method.center();
$(window).bind('resize.modal', method.center);
$modal.show();
$overlay.show();
};
// Close the modal
method.close = function() {
// alert("Called close method");
$modal.hide();
$overlay.hide();
$content.empty();
$(window).unbind('resize.modal');
};
// Generate the HTML and add it to the document
// $screen = $()
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="#">close</a>');
$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function() {
$('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );
function onStart ( touchEvent ) {
var flag = confirm("Are you sure want to defuse it?")
if (flag == true) {
$('#bombImg').attr('src', 'img/undefused.png');
} else {
$('#bombImg').attr('src', 'img/bomb01.png');
}
touchEvent.preventDefault();
modal.close();
}
});
return method;
}());
// Wait until the DOM has loaded before querying the document
//this method calling from another HTML file
function showDialog(e) {
disableZoomButtons();
$.get('popUp.html', function(data) {
modal.open({
content : data
});
});
document.ontouchmove = function(e) {
return false;
}
modal.open({
content : "<div id='imgDiv'><img id='bombImg' src='img/bomb01.png'/><br>"
+ "</div>"
});
e.preventDefault();
}
请任何人帮助我解决这个问题。我在安卓4.0+中运行这个应用程序
你必须
将onStart()
函数放在doc ready
之外:
function onStart ( touchEvent ) {
var flag = confirm("Are you sure want to defuse it?")
if (flag == true) {
$('#bombImg').attr('src', 'img/undefused.png');
} else {
$('#bombImg').attr('src', 'img/bomb01.png');
}
touchEvent.preventDefault();
modal.close();
}
$(document).ready(function() {
$('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );
});
相关文章:
- Angular$scope在模式窗口内不起作用
- JS-窗口宽度函数不起作用
- 剑道UI下拉列表在剑道窗口内不起作用
- 执行angularJS窗口警报不起作用
- FB.login有效,但弹出窗口不起作用;t关闭
- PHP变量作为Javascript弹出窗口不起作用
- 弹出窗口不起作用(未打开)Java 小程序
- 为什么简单的 JQuery 对话框/弹出窗口不起作用
- jQuery 模型弹出窗口不起作用
- ExtJS 窗口不起作用
- jQuery弹出窗口不起作用 - 简单的自定义弹出窗口
- Javascript弹出窗口不起作用
- JavaScript 确认弹出窗口不起作用
- 为什么在 Indesign 中关闭窗口不起作用
- Gmaps4Rails-自定义信息窗口不起作用
- window.focus()对父窗口不起作用
- Jquery 弹出窗口将选定的复选框值传递到父窗口不起作用
- 关闭引导弹出窗口不起作用
- 语义 UI 动态弹出窗口不起作用
- 关闭ajax弹出窗口不起作用