使用JQuery加载图像时显示预加载程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用JQuery加载图像时显示预加载程序相关的知识,希望对你有一定的参考价值。

Thank you marcg for posting this on Snipplr http://stackoverflow.com/questions/1379994/detect-when-a-specific-image-has-finished-loading
  1. <script>
  2. $(function () {
  3. var img = new Image();
  4. $(img).load(function () {
  5. $(this).hide();
  6. $('#loader').removeClass('loading').append(this);
  7. $(this).fadeIn();
  8. }).error(function () {
  9. // notify the user that the image could not be loaded
  10. }).attr('src', 'http://farm3.static.flickr.com/2405/2238919394_4c9b5aa921_o.jpg');
  11. });
  12. </script>

以上是关于使用JQuery加载图像时显示预加载程序的主要内容,如果未能解决你的问题,请参考以下文章