用jQuery显示加载指示器
我在
。 有12张图片,加载所有图片需要一些时间。 当图像加载时,我想显示加载的GIF图像。 我怎么能用jQuery做到这一点? 我的代码是:
您可以将侦听器绑定到每个映像的load事件。 使用计数器或其他机制来跟踪每次调用侦听器时加载的图像数量。 然后在加载最后一个图像后隐藏加载指示器。 例如:
HTML
jQuery的
$(function() { var images = $('.large-image') , total = images.length , count = 0; $('#loading').show(); images.load(function() { count = count + 1; if (count >= total) { $('#loading').hide(); } }); });
你可以在jsFiddle上看到这个例子: http : //jsfiddle.net/hallettj/ZefaM/
您可以使用jQuery load()函数。 一旦图像加载,它将运行代码。 因此,如果你有一个显示的GIF,一旦图像加载,它将隐藏它。
使用Javascript
$('img#id').load(function(){ $('#loadingGif').hide(); });
HTML
这就是你需要的: http : //jqueryfordesigners.com/image-loading/
如果您通过AJAX加载所有图像,请使用以下方式
HTML
jQuery的
$('#loadingDiv') .hide() // hide it initially .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ;
Interesting Posts
canvas图像无法在Chrome中呈现(适用于FF4和IE9)
Fullcalendar 2无法渲染,Bootstrap 3和Rails 4不兼容? (包括Jsfiddle)
多个输入的jQuery Datepicker
为什么多个ajax查询循环运行成功两次?
使用parsley.js为每个字段提供多个自定义错误消息支持
将JSON数据加载到Bootstrap模式中
使用Moment.js和Ordering Plugin在Datatable中按日期排序(dd.mm.YYYY)的问题
使用Javascript实时读取txt文件
对可变数量的ajax请求使用jquery deferreds
Javascript XML Parser