简体   繁体   English

jQuery Mobile:在过渡之前加载页面DIV

[英]Jquery Mobile: Load page DIV before transition

Hello!! 你好!!

i have a question and i haven't found any solution for it anywhere... 我有一个问题,我在任何地方都没有找到任何解决方案...

So, I have a button that link to internal div page (#page2) with a very long list, I need that the internal div page will be "loaded" before the transition will start... 因此,我有一个链接到具有很长列表的内部div页面 (#page2)的按钮,我需要在过渡开始之前“加载”内部div页面...

Here is a very simple Sample Code: 这是一个非常简单的示例代码:

<!-- Page #1 -->
<!-- ... -->
        <div data-role="content">    
        <p>View internal page: <a href="#page2">goto Page 2</a></p>
         </div>
<!-- ... -->
    <!-- Start of Page #2 -->
    <div data-role="page" id="page2">
        <div data-role="header">
            <h1>Bar</h1>
        </div><!-- /header -->
        <div data-role="content">   
    <ul><li>...</li>
    <li>...</li>
    <!-- About 300+ of: <li>...</li> -->
    </ul>
    </div>

So, Clicking over The link to #page2 should give you jquery mobile "Loading..." And after it "loaded" the content the transition should begin.. The reason Im doing it in the same page it that im inserting to the page#2 div dynamically all facebook friends (Long list), and it take a long time from the Click and until the transition begin... 因此, 单击指向#page2的链接应为您提供jquery mobile“正在加载...”,并且在它“加载”了内容之后,过渡应该开始了。原因是我在同一页面中执行此操作,因此我将其插入到页面中#2 div动态地所有Facebook好友(长列表),并且从单击到过渡开始需要很长时间...

Here is a nice example of what i need: http://www.mpdtunes.com Just go to: Live Demo-> Login -> Click Artists... 这是我需要的一个很好的例子: http ://www.mpdtunes.com只需转到:现场演示->登录->单击艺术家...

Any suggestions are welcome! 欢迎任何建议!

Thank you very much!!!! 非常感谢你!!!!

Basically you want to do this: 基本上,您想这样做:

  1. Use button like this: 使用这样的按钮:

     <a href="#" id="to-page2">goto Page 2</a> 
  2. Add a click event to it: 向其添加点击事件:

     $(document).on('pagebeforeshow', '#index', function(){ $(document).on('click', '#to-page2', function(){ // Load internal page content }); }); 

    Where #index is an id of your button containing page. 其中#index是您的按钮包含页面的ID。

  3. Show loading animation aka ajax loader 显示加载动画又名Ajax加载器

     setTimeout(function(){ $.mobile.loading('show'); },1); 

    SetTimeout is needed because web-kit browsers have a problem with dynamically triggered ajax loader. 需要SetTimeout ,因为Web工具包浏览器在动态触发Ajax加载程序时遇到问题。

  4. Load your internal page content. 加载您的内部页面内容。 Now if you are using 1 HTML page with multiple pages you can append new content to listview immediately. 现在,如果您将1个HTML页面与多个页面一起使用,则可以立即将新内容附加到listview。 This is because listview is already loaded into the DOM. 这是因为listview已经加载到DOM中。 If you are using several HTML pages then store your page content into localstorage variable. 如果您使用多个HTML页面,则将页面内容存储到localstorage变量中。

  5. Hide ajax loader, again with setTimeout. 隐藏ajax加载器,再次使用setTimeout。

  6. Start page transition with: 开始页面转换:

     $.mobile.changePage("#page2"); 
  7. If you have 1 HTML page then this is it. 如果您有1个HTML页面,那么就是这样。 If you have stored your page content inside a localstorage then you will need to load it during the pagebeforeshow event of a second page, like this: 如果您将页面内容存储在本地存储中,则需要在第二个页面的pagebeforeshow事件期间加载它,如下所示:

     $(document).on('pagebeforeshow', '#page2', function(){ // Load internal page content from local-storage and append it }); 
  8. Last step is listview page content initialization. 最后一步是listview页面内容初始化。 For that look at my other answer , just look for a topic regarding listview. 为此,请查看我的其他答案 ,只需查找有关listview的主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM