我正在开发一种小型嵌入式应用程序,它使用不支持多点触控手势的电阻式触摸屏(ADS 7846)。
问题在于,当使用手指(或其他物体)触摸屏幕时,mousedown事件仅在释放手指时才会被触发,如果mousedown和mouseup事件仅在手指被移除时才被触发。
function $(id) {return document.getElementById(id)};
$("butsetup").addEventListener("mousedown", function(e) {
alert('down');
});
$("butsetup").addEventListener("mouseup", function(e) {
alert('up');
});
是否有解决方案让这项工作符合预期?
根据@antyrat的建议,这报告是真的:
alert( 'ontouchstart' in document.documentElement )
但我在某处看到某些浏览器会曝光' dom的这种能力,但不启用它?
答案 0 :(得分:0)
是的,您可以使用touchstart
和touchend
个活动:
$("butsetup").addEventListener( ('ontouchstart' in document.documentElement) ? "touchstart" : "mousedown", function(e) {
alert('down');
});
$("butsetup").addEventListener( ('ontouchstart' in document.documentElement) ? "touchend" : "mouseout", function(e) {
alert('up');
});
答案 1 :(得分:0)
使用touchstart
和touchend
个活动。
$("butsetup").addEventListener("touchstart", function(event){
alert('touchstart');
}, true);
$("butsetup").addEventListener("touchend", function(event){
alert('touchend');
}, true);