gpt4 book ai didi

Javascript touchleave 和 touchcancel 不填充

转载 作者:行者123 更新时间:2023-12-03 06:41:01 32 4
gpt4 key购买 nike

Javascript触摸事件是这样的:touchstart、touchend、touchmove、touchleave、touchcancel。我在 div 元素“#panel”上移动手指。

$(document).ready(function(){

$("#panel").on('touchstart', function(e){
e.preventDefault();

$("#start-message").append("<p>Touch started</p>");
});

$("#panel").on('touchend', function(e){
e.preventDefault();

$("#end-message").append("<p>Touch end</p>");
});

$("#panel").on('touchmove', function(e){
e.preventDefault();

$("#move-message").append("<p>Touch moving...</p>");
});

$("#panel").on('touchleave', function(e){
e.preventDefault();

$("#leave-message").append("<p>Touch leaved.</p>");
});

$("#panel").on('touchcancel', function(e){
e.preventDefault();

$("#cancel-message").append("<p>Touch cancelled.</p>");
});
});

我正在使用 Chrome F12 开发工具来模拟触摸事件。我上传到服务器并在手机浏览器(不是chrome)上尝试。 touchstart、touchend 和 touchend 事件工作正常。但我无法填充 touchleave 和 touchcancel。 Working DEMO.

最佳答案

From docs, A user agent must dispatch this event type to indicate when a touch point has been disrupted in an implementation-specific manner, such as a synchronous event or action originating from the UA canceling the touch, or the touch point leaving the document window into a non-document area which is capable of handling user interactions. (e.g. The UA's native user interface, plug-ins) A user agent may also dispatch this event type when the user places more touch points on the touch surface than the device or implementation is configured to store, in which case the earliest Touch object in the TouchList should be removed.

根据我的个人实验,在 touchmove 处理程序运行时,在Chrome F12 开发工具中调用 touchcancel,启动右键单击

在 Android 5.1 中,在调用 touchmove 处理程序时按 lock-keyMinimize-key

注意:另请参阅Different ways to trigger touchcancel in mobile browsers

对于touchleave事件规范早期版本中的一项提案,尚未实现。不要依赖它。[来自 MDN]

关于Javascript touchleave 和 touchcancel 不填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959622/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com