2012-08-12 99 views
2

如何在加载期间显示gif图像?使用get()加载页面之前的图像加载

我用get。

function getCurrentUrl() { 
    $(
     $.get(
      "page1.html", 
      function (data) { 
       $("#divReceptLoad").empty().append(data); 
      }, 
      'html' 
     ) 
    ); 
} 

比你非常多,如果你能帮助我:)

+0

喜欢这个? http://jquerybyexample.blogspot.com/2012/06/show-loading-image-while-page-is.html – 2012-08-12 11:35:58

回答

4

创建<img id="loading" src="..." style="display:none;" />则:

function getCurrentUrl() { 
    $('#loading').show(); //show it before sending the ajax request 
    $.get("page1.html", function (data) { 
     $('#loading').hide(); //hide in the callback 
     $("#divReceptLoad").empty().append(data); 
    },'html')); 
} 

随意更多的样式/定位添加到图像和更换基本show/hide方法fadeIn/fadeOut,slideDown/slideUpother effects如果你喜欢。

这里有一个loading GIF generatoranother以防你不想从Google图片中获取一个。

这里是预制的nice collection

+0

+1,_如果你喜欢._? :) – undefined 2012-08-12 11:47:03

+1

@Raminson烨,谢谢。 '=]' – 2012-08-12 11:52:42

1
function getCurrentUrl() { 
    $('#gif').fadeIn() // show the hidden gif 
    $.get("page1.html", function(data){ 
     $('#gif').hide() // hide it 
     $("#divReceptLoad").empty().append(data); 
    },'html')  
}