views:

350

answers:

1

Is there a way to attach a loading gif, using Jquery, anytime any image on my site within a certain div is loading? I would like for it to be a global function, the only way I can seem to figure to do this is using jquery to call a certain link, and then load the loading.gif but that won't work in my situation…

Index 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>

Called 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();
    });
});

Thanks in advance

A: 

you can hook-up beforeSend property to attach handler to show loading indicator. You can get more information here.

TheVillageIdiot