$(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");
});
});
iveは上記のコードを見つけました。画像を読み込むことができる要素が欲しいのですが、画像が完全に読み込まれる前に、読み込み中のgifを表示したいと思います(これはcssを使用して行います)。動作しますが、完全に読み込まれるのを待つのではなく、画像の読み込みが表示されます。アラートがhide()show()を使用している画像を表示する必要があると思いますが、関数内からそれを参照する方法がよくわかりませんか?
iveは運が悪かったのでこれを試しました、誰かが何か問題を見ます>?gifの読み込みに同じdivを使用してから、最終的な画像を使用したい
$('#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?
});