2009-09-11 99 views
0

有沒有辦法在我的網站上的某個div內加載任何圖像時,使用Jquery附加加載gif?我想它是一個全局函數,我似乎可以做到這一點的唯一方法是使用jQuery來調用某個鏈接,然後加載loading.gif但這在我的情況下不起作用...JQuery全局加載動畫

指數HTML:

<div id="content"> 
    <div class="projectThumb"> 
    <img src="/img/aeffect_button_static.gif" name="aeffect" /> 
    <p class="title">title</p> 
    </div> 
</div> 
<div id="popupContainer"></div> 

稱爲HTML:

<div class="projectPopup" id="aeffect"> 
    <a class="close">Close &times;</a> 
    <img src="/img/aeffect_popup.jpg" width="500" height="729" alt="" /> 

    <p class="description">Description</p> 
</div> 

JQuery的:

$(document).ready(function() { 
    //Find & Open 
    $(".projectThumb").click(function(){ 
      $("#backgroundPopup").show(); 
      htmlName = $(this).find("img").attr("name"); 
      $("#popupContainer").load("/content/" + htmlName + ".html", null, function(){ 
      //Set Variables 
      var container = $(".projectPopup") 
      var popupWidth = container.find("img:first").width()+10; 
      var popupHeight = container.find("img:first").height()+60; 
      var windowWidth = document.documentElement.clientWidth; 
      var windowHeight = document.documentElement.clientHeight; 

      //Set popup dimensions 
      container.css("width" , popupWidth); 
      container.css("height" , popupHeight); 

      //Set popup CSS 
      container.css({"position": "absolute", "background": "#000", "top": "5%", "left": (windowWidth/2) - (popupWidth/2) + "px", "z-index": "2" }); 
      }); 
}); 
    //Close property 
    $("a.close").live("click", function(){ 
      $("#popupContainer").empty(); 
      $("#backgroundPopup").hide(); 
    }); 
}); 

在此先感謝

回答

0

您可以連接beforeSend屬性以附加處理程序以顯示加載指示器。您可以獲得更多信息here