您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/9/29 19:30:30发布18次查看
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实现图片依次加载实例代码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product