2009-09-11 107 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