jquery中的mousedown / mouseup适用于ipad吗?

发布于 2024-09-10 16:47:23 字数 263 浏览 4 评论 0原文

我正在使用当前的代码:

$('body').mousedown(function() {
        $('div#extras').fadeTo('fast', 1);
});

$('body').mouseup(function() {
        $('div#extras').delay(2000).fadeTo(1500, 0);
});

这在 safari 中效果很好,但是当我上传它并在 ipad 上查看时它不起作用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

变身佩奇 2024-09-17 16:47:23

我发现了如何为那些感兴趣的人在 ipad 上执行此操作:

您可以使用:而不是我在问题中使用的代码:

$('body').bind( "touchstart", function(e){
        $('div#extras').fadeTo('fast', 1);
});

&

$('body').bind( "touchend", function(e){
        $('div#extras').delay(2000).fadeTo(1500, 0);
});

I found out how to do this for the ipad for those who are interested:

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);
});
草莓酥 2024-09-17 16:47:23

不完全是。

苹果文档

引用:

可点击元素是链接、表单元素、图像映射区域或任何其他带有
mousemove、mousedownmouseup 或 onclick 处理程序。可滚动元素是任何
具有适当溢出样式、文本区域和可滚动 iframe 元素的元素。
由于这些差异,您可能需要将一些元素更改为
可点击元素,如“使元素可点击,”以获得所需的
iPhone 操作系统中的行为。

(强调我的)

Not exactly.

Apple Docs

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.

(emphasis mine)

他不在意 2024-09-17 16:47:23

没有真正回答你的问题,但对于那些来这里只是为了寻找“ipad 上的 jQuery mousedown/mouseup”的人来说可能很方便

我总是使用这个小技巧:

$(element).hover(function() {
   // Do something
});

当使用 iPad 时,这会触发触摸,并在使用时反转操作单击元素外部,因为它是悬停事件。例如:

// Assuming the element has 'opacity: 0' in CSS

$(element).hover(function() {
   $(this).animate({'opacity': 1}, 200);
});

“单击时”创建淡入效果,“鼠标松开时”创建淡出效果。

Not really answering your question, but may be handy for people who came here just to look for 'jQuery mousedown/mouseup on ipad'

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 element since it's an hover event. So for example:

// 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'.

白云不回头 2024-09-17 16:47:23

老帖子,但有通用的解决方案:

$('body').on('mousedown touchstart',function(e){
    $('div#extras').fadeTo('fast', 1);
});
$('body').on('mouseup touchend',function(e){
    $('div#extras').delay(2000).fadeTo(1500, 0);
});

您会注意到我将 mousedowntouchstart 一起使用,将 mouseuptouchend 一起使用。这涵盖移动和桌面使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文