Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 加载JQM页面后TouchSweep未正确启动_Jquery_Jquery Mobile_Touchswipe - Fatal编程技术网

Jquery 加载JQM页面后TouchSweep未正确启动

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 = {

我正在使用JQM创建一个混合应用程序。其中一页是我使用的图像库

如果我直接打开页面,一切正常。但是,如果我通过单击另一个页面的链接导航到此页面,JQM将使用Ajax加载该页面,并且
滑动
未正确初始化。如果我尝试刷卡,会出现以下错误:

只有当我按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之后加载的。