2012-06-03 37 views
4

我在嘗試複製jQuery Mobile的頁面導航系統,其中您可以調用加載到容器中的dom頁面,然後將該容器漂浮到右側,然後生成以下代碼到目前爲止:http://s46264.gridserver.com/dev/dave/pageslider/.load()頁面並預加載所有內容

我的問題是,我想在調用動畫語句之前預加載所有頁面內容(請參閱加載頁面2)我該怎麼做?到目前爲止

代碼:

var currPage = "one"; 

     function loadPage(newPage) { 
      $("<div id='" + newPage + "' class='page'></div>").insertAfter('#'+currPage); 
      $('#'+newPage).load('pages/' + newPage + '.php', function() {  
       $('#page_wrapper').animate({ 
        left: '-400px' 
       }, 200, function() { 
        $('#'+currPage).remove(); 
        $('#page_wrapper').css('left',0); 
        currPage = newPage; 
       }); 
      }); 
     } 

     $(document).ready(function() { 
      $("#page_wrapper").append("<div id='" + currPage + "' class='page'></div>"); 
      $('#'+currPage).load('pages/' + currPage + '.php'); 
     }) 

而且,我很新,所以在我的方法上的錯誤任何提示的好評。

感謝

+0

不是你要的腳本做什麼? – BishopZ

+0

在他的示例中,第2頁上的圖像只在div滑入時加載。他想知道他是否可以預加載此內容,以便在頁面滑入時圖像已經存在。 –

回答

0

請看下面的解決方案:

http://chipsandtv.com/articles/jquery-image-preload

,你是否嘗試去在你已經預裝在DOM所有的圖像標籤,並在內存中創建圖像元素具有以下內容:

// images is an array with the image filenames, so you'd 
// have to extract these from the preloaded source. 
$(images).each(function() { 
    var image = $('<img />').attr('src', this); 
}); 

這當然假設​​還沒有顯示這個特定的b ehavior。

相關問題