jQuery Mobile等待整个页面加载完成

jQuery Mobile等待整个页面加载完成,jquery,jquery-mobile,Jquery,Jquery Mobile,我对jquerymobile的问题是,在实际加载页面之前,如何等待页面完全加载(所有图像、文本)。为了澄清这一点,一旦用户单击链接,加载图形将在页面加载时保留在屏幕上,一旦完全加载,则隐藏加载图形并加载页面 这可能吗 $(document).on('click', '.my-custom-links', function() { //get the requested page $.ajax({ url : this.href, succe

我对jquerymobile的问题是,在实际加载页面之前,如何等待页面完全加载(所有图像、文本)。为了澄清这一点,一旦用户单击链接,加载图形将在页面加载时保留在屏幕上,一旦完全加载,则隐藏加载图形并加载页面

这可能吗

$(document).on('click', '.my-custom-links', function() {
    //get the requested page
    $.ajax({
        url     : this.href,
        success : function (page) {
            //get only the first data-role="page" element
            var $page = $(page).find('[data-role="page"]').first();

            //now bind an event handler to all the elements that will need to load
            var $assets       = $page.find('img, script, link'),
                assets_loaded = 0;

            //make sure to bind to the load event before adding the element to the DOM
            $assets.on('load', function () {
                assets_loaded++;
                if (assets_loaded == $assets.length) {
                    //all the assets have loaded, so navigate to the new page
                    $.mobile.changePage($page);
                }
            });

            //add new page to the DOM
            $.mobile.pageContainer.append($page)
        },
        error   : function (jqXHR, textStatus, errorThrown) { /*Don't forget to handle errors*/ }
    });
    return false;
});

这是第一条裂缝。基本想法与@Kevin B.的评论相差不远。Hi jack点击某些链接,抓取指向链接的页面,将其添加到DOM中,然后仅在资产加载后显示。

这是可能的,但您必须通过监听所述链接的点击事件、手动检索和附加页面、解析图像/脚本/css来手动执行,然后确认它们都已完成加载。