$(document).ready(function(){
// The plugin
$.fn.image = function(src, f){
return this.each(function(){
var i = new Image();
i.src = src;
i.onload = f;
this.appendChild(i);
});
}
// The code for the image to load
$("#asdf").image("images/3a.jpg",function(){
alert("The image is loaded now");
});
});
我找到了上面的代碼。我想有一個可以加載圖像的元素,但在圖像完全加載之前,我希望它顯示加載gif,(使用css完成此操作)。它的工作原理,但會顯示圖像加載,而不是等待它被完全加載。 我想我應該顯示圖像警報正在使用hide()show()但我不太清楚如何從函數內引用它?帶有預加載圖像的jquery圖像
我試過這個沒有運氣,有人看到有什麼問題>? 我想使用同一div的加載GIF那麼最終的圖像
$('#preload').replaceWith('<img src="preloader.gif" />')
.image("http://www.google.co.uk/intl/en_uk/images/logo.gif", function() {
$('#preload').replaceWith(this);
// is this called when image fully loaded?
});
我刪除了我原來的答覆,因爲我錯過了圖像WASN不會被替換,而是被注入到DIV中。我的答案在後面的例子中不起作用。 – tvanfosson 2009-06-07 19:26:10