iPad 版 Safari 上的 Web 应用程序:取消 touchmove 上的 touchstart

发布于 2024-11-17 15:59:39 字数 1362 浏览 0 评论 0原文

这似乎是一个简单的解决方案,但当谈到 iPad 上的触摸功能时,我有点菜鸟。

我理解我需要做什么的概念,我只是不知道语法。

问题:我有一个页面充满了 DIV。这些 DIV 被包装在 iScroll4 包装器中。 iScroll 脚本设置得很好,如果您通过点击和移动链接来开始滚动页面,则该链接永远不会触发。

然而我却没那么优秀。因为我设置了一些 jQuery 代码来为“touchstart”上的 DIV 之一设置动画,但问题是,即使我滚动或拖动手指,动画也会在我不希望的情况下触发。

我需要设置超时或取消触摸启动。或者在 touchend 上触发动画,但如果将手指拖动 x 像素量并将该触摸转换为触摸移动,则取消触摸。

有谁知道该怎么做?提前致谢!

Alex

编辑:这是我当前的 jQuery 代码。如果我将手指拖动 X 个像素,我需要取消触发动画功能。可能使用 pageX 和 pageY?

    $('tr#recent').live("touchend click", function () {
        $(".modalWindow").css('display', 'block').animate({
                height:716,
                top:15,
                left:15,
                width:995
            }, 300);            
    });

以下是雅虎如何使用其 Scrollview 做到这一点: http://developer.yahoo .com/yui/3/examples/scrollview/scrollview.html

var content = scrollView.get("contentBox"); 

content.delegate("click", function(e) {
    // Prevent links from navigating as part of a scroll gesture
    if (Math.abs(scrollView.lastScrolledAmt) > 2) {
        e.preventDefault();
        Y.log("Link behavior suppressed.")
    }
}, "a");

看看他们如何检查“lastscrolled”数量,然后在您将手指拖动一定距离时取消链接行为......但我是不使用滚动视图....

This might seem like a simple solution, but I am kinda of a n00b when it comes to this touch stuff on the iPad.

I understand the concept of what I need to do, I just don't know the syntax.

Problem: I have a page full of DIV's. These DIV's are wrapped in an iScroll4 wrapper. The iScroll script is set up nicely where if you were to start scrolling the page by tapping and moving a link, the link would never fire.

I, however, am not that good. Because I set up some jQuery code to animate one of the DIV's on "touchstart" but the problem is that even if I scroll or drag my finger, the animation fires even when I don't want it to.

I need to set a time out or cancel the touchstart. Or fire the animation on touchend, but cancel the touch if you drag your finger x amount of pixels and turn that touch into a touchmove.

Does anyone know how to do that? Thanks in advance!

Alex

EDIT: Here is my current jQuery code. I need to cancel the animation function from firing if I drag my finger X amount of pixels. Probably using pageX and pageY?

    $('tr#recent').live("touchend click", function () {
        $(".modalWindow").css('display', 'block').animate({
                height:716,
                top:15,
                left:15,
                width:995
            }, 300);            
    });

Here is how Yahoo does it with their Scrollview: http://developer.yahoo.com/yui/3/examples/scrollview/scrollview.html

var content = scrollView.get("contentBox"); 

content.delegate("click", function(e) {
    // Prevent links from navigating as part of a scroll gesture
    if (Math.abs(scrollView.lastScrolledAmt) > 2) {
        e.preventDefault();
        Y.log("Link behavior suppressed.")
    }
}, "a");

See how they are checking the "lastscrolled" amount and then canceling the link behavior if you drag your finger a certain distance.....But I am not using Scrollview....

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

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

发布评论

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

评论(1

花开浅夏 2024-11-24 15:59:39

如果您想停止触发默认事件,则需要取消它。阅读 jQuery 事件对象,特别是 event.preventDefault() 和event.stopPropagation()。另一个技巧是在函数末尾添加 false,因此...

$( 'div' ).bind( 'touchstart', function(e)
{
    // do some funky stuff

    return false; // this'll cancel the default behaviour of the event
});

通常,如果您想做更多事情,您可以为“touchmove”添加另一个绑定来获取移动的 X 和 Y。

If you want to stop the default event from firing then you need to cancel it. Have a read of the jQuery event object, especially event.preventDefault() and event.stopPropagation(). Another trick is to add false to the end of the function, so...

$( 'div' ).bind( 'touchstart', function(e)
{
    // do some funky stuff

    return false; // this'll cancel the default behaviour of the event
});

Usually, if you want to do some more stuff, you'd add another bind for 'touchmove' to get the X and Y of the movement.

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