English 中文(简体)
带有预载图像的频率图像
原标题:
  • 时间:2009-06-07 18:53:27
  •  标签:
$(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 found the above code. I want to have an element that can be loaded with an image, but before the image is fully loaded i want it to show a loading gif, (done this using css). It works but will show the image loading instead of waiting for it to be fully loaded. I think i should be showing the image where the alert is using hide() show() but im not quite sure how to reference it from inside the function?


ive tried this with no luck, anyone see any problems>? i want to use the same div for the loading gif then the final image

$( #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?
          });
问题回答

你可能想尝试使用「延迟加载」插件(或类似的插件)来代替。请注意,你可以指定自己的占位图像。

你可以尝试这样的事情:

    var $loadingImg = $( <img /> ).attr( id , loadingImg ).attr( src , preloader.gif );
    $("#preload").html($loadingImg.html()).image("http://www.google.co.uk/intl/en_uk/images/logo.gif");

让我知道这怎么办。

发现一幅完全看似的图象,使用一位持照人的形象,然后充分显示最终形象。

rel=“nofollow noreferer” http://flesler.blogspot.com/2008/01/jquerypreload.html





相关问题
热门标签