Jquery移动与滚动动画冲突

时间:2013-06-04 14:03:07

标签: jquery jquery-mobile jquery-animate

<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

我已经在我的网站中包含了JQuery mobile来启用tap事件(上图),但是这样做似乎与我在下面的代码中使用的.animate冲突,而不是很好地动画到顶部它跳转到元素顶部的元素。任何人都可以看到有什么问题吗?

           $(document).on('tap click', '.team-btn', function(event){                          
             event.preventDefault();            
                    $('html, body').stop(true,true).animate({
                         scrollTop: $(".team-overlay").offset().top - 20
                     }, 2000);  
        });

1 个答案:

答案 0 :(得分:1)

包含jQuery Mobile就像这样是一个很大的错误,主要是因为如果你不知道它是如何工作的,它会给你带来很多问题。它将基本上接管您的网络应用程序。

如果您只需点按活动,请转到此链接:http://jquerymobile.com/download-builder/

重建jQuery Mobile,只使用点击功能(称为触摸 - 触摸事件,包括:touchstart,touchmove,touchend,tap,taphold,swipe,swipeleft,swiperight,scrollstart,scrollstop)。 Builder将选择其他依赖项。

这将删除不需要的功能。

或者跳过jQuery Mobile并使用 Hammer.js ,它拥有更多支持的触摸,众多和滑动事件,并且它适用于jQuery。

您的语法如下所示:

$(document).hammer().on("tap click", ".team-btn", function(event) {
    // Your code
});