最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

jquery实现图片依次加载实例代码

来源:懂视网 责编:小采 时间:2020-11-27 20:17:02
文档

jquery实现图片依次加载实例代码

jquery实现图片依次加载实例代码:css代码:ul#portfolio{margin:0;padding:0;} ul#portfolio li{float: left;margin:0 5px 0 0;width:250px;height: 250px;list-style: none;} ul#portfolio li.loading{background: url(../image
推荐度:
导读jquery实现图片依次加载实例代码:css代码:ul#portfolio{margin:0;padding:0;} ul#portfolio li{float: left;margin:0 5px 0 0;width:250px;height: 250px;list-style: none;} ul#portfolio li.loading{background: url(../image

css代码:

ul#portfolio{margin:0;padding:0;}
ul#portfolio li{float: left;margin:0 5px 0 0;width:250px;height: 250px;list-style: none;}
ul#portfolio li.loading{background: url(../images/spinner.gif) no-repeat center center;}
ul#portfolio li img{width:250px;height: 250px;display: block;}

js代码:

$(function(){var images=new Array();
 images[0]='./images/ads_one.jpg';
 images[1]='./images/ads_two.jpg';
 images[2]='./images/ads_three.jpg'; //获取了图像的数量var max=$(images).length; 
 //如果包含一张以上的图像,那么创建对应的UL元素家人到wrapper div中,并且调用LoadImage方法。 if(max>0){
 //create the UL elementvar ul=$('<ul id="portfolio"></ul>');//append to div#wrapper$(ul).appendTo($('#wrapper'));
 //load the first imageLoadImage(0,max);
 } //在LoadImage方法中,循环遍历所有的图像,对每个图像创建li元素function LoadImage(index,max){ 
 if(index<max){ //利用attr方法为li元素增加了css样式,即加上了loading的gif背景。 
 var list=$('<li id="portfolio_'+index+'"></li>').attr('class','loading'); 
 //把li添加到ul元素中 $('ul#portfolio').append(list); 
 //获取当前的li元素 var curr=$("ul#portfolio li#portfolio_"+index); 
 //创建图像元素 var img=new Image(); 
 //加载图像 $(img).load(function(){
 $(this).css('display','none');
 $(curr).removeClass('loading').append(this);
 $(this).fadeIn('slow',function(){
 //采用回调函数的方法,在当前元素成功执行fadeIn方法之后 再去调用下一个元素的LoadImage方法,这样就能实现多个图像的顺序加载了。LoadImage(index+1,max);
 });
 }).error(function(){
 $(curr).remove();
 LoadImage(index+1,max);
 }).attr('src',images[index]);
 }
 }
})

文档

jquery实现图片依次加载实例代码

jquery实现图片依次加载实例代码:css代码:ul#portfolio{margin:0;padding:0;} ul#portfolio li{float: left;margin:0 5px 0 0;width:250px;height: 250px;list-style: none;} ul#portfolio li.loading{background: url(../image
推荐度:
标签: 图片 加载 实现
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top