jquery 中的 mousedown /mouseup 是否适用于 ipad?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3303469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
does mousedown /mouseup in jquery work for the ipad?
提问by Annie
I am using the current code:
我正在使用当前代码:
$('body').mousedown(function() {
$('div#extras').fadeTo('fast', 1);
});
$('body').mouseup(function() {
$('div#extras').delay(2000).fadeTo(1500, 0);
});
This works great in safari but when I upload it and check it out on the ipad it doesnt work?
这在 safari 中效果很好,但是当我上传它并在 ipad 上查看时它不起作用?
回答by Annie
I found out how to do this for the ipad for those who are interested:
我为感兴趣的人找到了如何为 ipad 执行此操作:
Instead of the code I used in my question, you would use:
而不是我在我的问题中使用的代码,您将使用:
$('body').bind( "touchstart", function(e){
$('div#extras').fadeTo('fast', 1);
});
&
&
$('body').bind( "touchend", function(e){
$('div#extras').delay(2000).fadeTo(1500, 0);
});
回答by scunliffe
Not exactly.
不完全是。
Quote:
引用:
A clickable element is a link, form element, image map area, or any other element with mousemove, mousedown, mouseup, or onclick handlers. A scrollable element is any element with appropriate overflow style, text areas, and scrollable iframe elements. Because of these differences, you might need to change some of your elements to clickable elements, as described in “Making Elements Clickable,” to get the desired behavior in iPhone OS.
可点击元素是链接、表单元素、图像映射区域或任何其他具有 mousemove、mousedown、mouseup或 onclick 处理程序的元素。可滚动元素是具有适当溢出样式、文本区域和可滚动 iframe 元素的任何元素。由于这些差异,您可能需要将某些元素更改为可点击元素,如“使元素可点击”中所述,以在 iPhone 操作系统中获得所需的行为。
(emphasis mine)
(强调我的)
回答by Jeffrey Roosendaal
Not really answering your question, but may be handy for people who came here just to look for 'jQuery mousedown/mouseup on ipad'
没有真正回答你的问题,但对于来这里只是为了寻找“ipad 上的 jQuery mousedown/mouseup”的人来说可能很方便
I always use this little trick:
我总是用这个小技巧:
$(element).hover(function() {
// Do something
});
This triggers on touch when using an iPad and reverses the action when clicking outside of the elementsince it's an hover event. So for example:
这在使用 iPad 时在触摸时触发,并在元素外部单击时反转动作,因为它是悬停事件。例如:
// Assuming the element has 'opacity: 0' in CSS
$(element).hover(function() {
$(this).animate({'opacity': 1}, 200);
});
Creates a fade in effect 'on click', and a fade out effect 'on mouseup'.
创建“单击时”淡入效果和“鼠标抬起时”淡出效果。
回答by Ivijan Stefan Stipi?
Old post but there is universal solution:
旧帖子,但有通用的解决方案:
$('body').on('mousedown touchstart',function(e){
$('div#extras').fadeTo('fast', 1);
});
$('body').on('mouseup touchend',function(e){
$('div#extras').delay(2000).fadeTo(1500, 0);
});
You will notice that I use mousedown
with touchstart
and mouseup
with touchend
. This cover mobile and desktop use.
您会注意到我使用mousedown
withtouchstart
和mouseup
with touchend
。这包括移动和桌面使用。