gpt4 book ai didi

javascript - ngSwipe 和水平滚动

转载 作者:可可西里 更新时间:2023-11-01 01:26:16 24 4
gpt4 key购买 nike

我在结合 ng-swipe 和移动设备上的水平滚动时遇到问题。用例是我有一个页面,滑动时应该加载下一个或上一个页面,里面有显示大量信息的模块。其中一些是滚动的。

因此,一旦您滚动到父项上的滑动,您就会开始导航。所以我用这种技巧在可滚动元素的父元素上放置了另一对 ng-swipe:

self.onInnerSwipe = function($event) {
$event.originalEvent.preventAction = true;
};

然后在父级上:

var shouldActionProceed = function($event) {
return !$event || !$event.originalEvent || !$event.originalEvent.preventAction;
};

self.goToPrev = function($event) {
if (shouldActionProceed($event)){
// Do Magic
}
}

如果我在该元素上滑动但滚动实际上不起作用,则该操作不会继续进行。有点像,但事实并非如此。它开始一点然后停止。

在 Chrome 上,有时会记录此警告。

Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.

我在这里准备了一个演示:http://jsbin.com/webologavu/2/这过于简单,但您可以重现该问题。

有什么提示吗?

最佳答案

我认为这是这些事件的并发问题。如果您的父事件不依赖于子事件,它可能会更好。要实现这一点:

//add a identifier to your list element
<ul class="myList" your-other-attrs></ul>

//should proceed can rely on the target element to find out
//if the target element belongs (or is) in your list.
var shouldActionProceed = function($event) {
return !$($event.target).hasClass("myList") && //is myList?
$($event.target).parents(".myList").length == 0; //has parent 'myList'?
};

这样,父事件就可以继续工作了。

关于javascript - ngSwipe 和水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30664124/

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