2013-02-19 66 views
2

我正在加載外部html與Ajax到一個頁面,這個外部圖像有一個大的背景圖像,我想加載gif顯示,直到背景圖像滿載,這可能嗎?不要顯示,直到背景圖像完全加載

可以SEEE什麼我正在這裏:

點擊播放>>>開始遊戲。

你會看到地圖加載的背景圖像的時刻

我的jQuery代碼如下:。

$(document).bind('ajaxStart', function(){ 
      $('#loading-image').show(); 
    }).bind('ajaxStop', function(){ 
      $('#loading-image').hide(); 
     }); 

    $('body').on('click', '.mch-ajax', function(e){ 
     e.preventDefault(); 
     $('#mch-overlay').fadeOut(300); 
     $("#loading-image").show(); 
     $(".content").load("game.html", function() { 
       $("#loading-image").hide(); 
     }); 
    }); 

謝謝!

回答

5

您可以檢測像這樣的圖像的負荷,

var myBackgroundImage = new Image(); 
myBackgroundImage.src = "/{Image Path}";  

myBackgroundImage.onload = function() { 
    //Now do what ever you need to as the image is loaded 
}; 
+0

我將如何適應我的代碼跟你提供了什麼?我不太確定。謝謝。 – user1937021 2013-02-19 23:31:30