Jquery 加载JQM页面后TouchSweep未正确启动
我正在使用JQM创建一个混合应用程序。其中一页是我使用的图像库 如果我直接打开页面,一切正常。但是,如果我通过单击另一个页面的链接导航到此页面,JQM将使用Ajax加载该页面,并且Jquery 加载JQM页面后TouchSweep未正确启动,jquery,jquery-mobile,touchswipe,Jquery,Jquery Mobile,Touchswipe,我正在使用JQM创建一个混合应用程序。其中一页是我使用的图像库 如果我直接打开页面,一切正常。但是,如果我通过单击另一个页面的链接导航到此页面,JQM将使用Ajax加载该页面,并且滑动未正确初始化。如果我尝试刷卡,会出现以下错误: 只有当我按F5并重新加载页面时,它才起作用 这是我使用的代码: $(document).on( "pagecontainerbeforeshow", function( e, ui ) { Gallery.init(); }); var Gallery = {
滑动
未正确初始化。如果我尝试刷卡,会出现以下错误:
只有当我按F5并重新加载页面时,它才起作用
这是我使用的代码:
$(document).on( "pagecontainerbeforeshow", function( e, ui ) {
Gallery.init();
});
var Gallery = {
imgContainer: null,
(...),
init: function() {
this.imgContainer = $('#imageContainer');
(...)
console.log('This msg shows');
this.imgContainer.swipe({
threshold : 100,
triggerOnTouchEnd: true,
allowPageScroll : "horizontal",
swipeStatus : function (event, phase, direction, distance, duration) {
Gallery.swipe(event, phase, direction, distance, duration)
}
});
},
swipe: function(...){
console.log('I only get this by hitting F5');
}
};
非常感谢您的帮助 因此,事实证明这是加载脚本的顺序。但并非如此 最初,我在我的图库页面上加载脚本:
// Header
<script src=jquery
<script src=jquery.mobile
//Footer
<script src=jquery.touchSwipe
//头
可能是pagecontainerbeforeshow无法启动(Gallery.init();),因为该页面尚未在Dom中。将($(document).on(“pagecontainerbeforeshow”)更改为($(document).on(“pagecontainertransition”)并查看它是否有助于Snope,仍然会得到相同的错误。Gallery.init()
激发。它甚至运行this.imgContainer.swipe()
,但是我得到了这个错误。检查这里,看看你是否以正确的方式加载了插件——我希望它这么简单。不幸的是,它是在jQuery和JQM之后加载的。