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

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

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

1 回答 1

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
});
于 2013-06-04T14:08:24.550 回答