2011-03-03 42 views

回答

2

你不需要jQuery就知道圖像何時加載。

// show animation that indicates image is loading 
    var test = new Image(); 
    test.onload = function() { 
     // this gets called when the image has loaded 
     // we need to place the image on the page: 
     $('#ImageContainerWhatever').append(test); 
     // and hide the loading animation 
    }; 
    test.src = 'my_image.png'; 

onload當瀏覽器加載圖像它不`噸,如果從網絡或本地緩存關係被調用。

看到那些例子:https://developer.mozilla.org/en/Canvas_tutorial/Using_images

+0

這是非常棒的,完美的工作。 – 2011-03-03 03:39:55

2

您可以將事件偵聽器添加到圖像的load事件中。

+0

做負載火如果圖像已經緩存? – Adrian 2011-03-03 03:26:43

+2

是的,我相信它。 – 2011-03-03 03:27:43

+1

這就是'$(image).load(function ...)',但我真的完全沒有在這裏看到對jQuery的需求,你通過輸入'on'保存的_two_字符(在IMG的'onload'中)得到_three_字符'$()'和使用jQuery的開銷。 – Trinidad 2011-03-03 03:43:48