【问题标题】:jquery mobile pageContainer to load external page with transition effectsjquery mobile pageContainer加载带有过渡效果的外部页面
【发布时间】:2014-07-12 16:02:35
【问题描述】:

我目前正在使用 jquery mobile v1.4.2 开发移动应用程序。 . . .几乎所有的功能都完成了。现在我想为所有页面添加过渡效果......

问题: 在 jquery mobile v1.4.2(doc)中告诉使用 pageContainer 而不是 pagechange 和 pageload,我不知道如何加载具有过渡效果的外部页面(另一个 HTML 文件)。我在 google 和任何参考中都没有找到必须的示例链接表示赞赏。

提前致谢

【问题讨论】:

    标签: jquery html jquery-mobile cordova


    【解决方案1】:
    1. 您可以使用以下代码轻松强制默认转换:

      <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
      <script>
          $(document).bind("mobileinit", function () {
              $.mobile.defaultPageTransition = 'slide';
          });
      </script>
      <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>   
      

      别忘了一件事,mobileinit 事件必须在 jQuery Mobile 之前初始化,就像我的例子一样。

    2. 关于你的第二个问题,你会这样做:

      $( ":mobile-pagecontainer" ).pagecontainer( "load", "second.html", { role: "page" } );
      

      例子:

      index.html

      <!DOCTYPE html>
      <html>
          <head>
              <title>jQM Complex Demo</title>
              <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
              <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
              <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" /> 
              <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
              <script>
                  $(document).bind("mobileinit", function(){
                      $.mobile.defaultPageTransition = "slide";
                  });            
              </script>
              <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
              <script>
                  $(document).on('pagecreate', '#index', function(){ 
                      $( ":mobile-pagecontainer" ).pagecontainer( "load", "second.html", { role: "page" } );
                  });     
      
              </script>       
          </head>
          <body>     
              <div data-role="page" id="index" data-theme="a" >
                  <div data-role="header">
                      <h3>
                          First Page
                      </h3>
                      <a href="#second" class="ui-btn-right">Next</a>
                  </div>
      
                  <div data-role="content">
      
                  </div>
      
                  <div data-role="footer" data-position="fixed">
      
                  </div>
              </div>  
          </body>
      </html>   
      

      second.html

      <div data-role="page" id="second" data-theme="a" >
          <div data-role="header">
              <h3>
                  Second Page
              </h3>
              <a href="#index" class="ui-btn-left">Back</a>
          </div>
      
          <div data-role="content">
      
          </div>
      
          <div data-role="footer" data-position="fixed">
      
          </div>
      </div> 
      

    【讨论】:

    • 感谢您的回复...我用您提供的 pagecotainer 替换了 window.location.href ="second.html" 但它不起作用...
    • 我给了你一个可行的例子,所以问题就在你身边。什么不适合你?
    • 是的,问题出在我这边,只是找不到解决方案,非常感谢您提供了很好的示例+1 ...感谢很多 gajotres
    • 我很高兴能够提供帮助:)
    • 加载外部页面是否需要初始化代码,例如 $.mobile.allowCrossDomainPages = true;和 $.support.cors =true;在移动初始化中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多