900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > jquery中图片无序预加载的实现以及使用方法

jquery中图片无序预加载的实现以及使用方法

时间:2021-11-30 00:50:43

相关推荐

jquery中图片无序预加载的实现以及使用方法

web前端|js教程

jquery

web前端-js教程

本篇文章给大家带来的内容是关于jquery中图片无序预加载的实现以及使用方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

在线视频辅导软件开源源码,ubuntu怎么撤销删除,recv爬虫详细讲解,php财务单据,三响seolzw

/图片无序预加载(function($){function Preload(imgs,fns){this.imgs=(typeof imgs==="string")?[imgs]:imgs;this.fns=$.extend({},Preload.fns,fns);//把fns 覆盖到Preload上 然后添加到{}返回if(this.fns.loadMethod=="unorderload"){//是无序 还是有序this._unorderload();}else{this._orderload();}}Preload.fns={loadMethod:null,//有序还是无序的方式eachLoadImg:null, //每张图片加载完所执行的函数allLoadImg:null //所有图片加载完所要执行的函数}Preload.prototype._orderload=function(){var imgs=this.imgs,len=imgs.length,fns=this.fns,num=0;function load(){var imgObj=new Image();$(imgObj).on("load error",function(){fns.each && fns.each(); //存在 才会执行if(num<len){load(); //没有加载完就继续加载 函数执行是有顺序的}else{fns.allLoadImg && fns.allLoadImg();//加载完全部}});imgObj.src=imgs[num];num++;}load();}Preload.prototype._unorderload=function(){var imgs=this.imgs,len=imgs.length,fns=this.fns,num=0;$.each(imgs,function(i,src){if(typeof src!="string") return;var imgObj=new Image();$(imgObj).on("load error",function(){fns.eachLoadImg && fns.eachLoadImg(num,len);if( num==len-1){fns.allLoadImg && fns.allLoadImg();}num++;});imgObj.src=src;});}$.extend({ //给jQuery上增加新函数preload:function(imgs,fns){new Preload(imgs,fns);}});})(jQuery);

使用方法

mtk平台 俄罗斯源码,U盘 修复 Ubuntu,爬虫主要学哪些,php如何调用外部php,seo级环保lzw

有序预加载*{margin: 0; padding: 0;} img{ width:100%; vertical-align:top; } .imgBox{ width:500px; margin:100px auto; } #prevImg, #nextImg{width:60px;font-size:15px;height:30px;line-height:30px;text-align:center;background: #686868;position:absolute;color:#000;text-decoration:none;margin-top:-50px; } #prevImg{ left:40%; } #nextImg{ left:55%;} $(function(){var imgs=["img/0.jpg","img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg","img/6.jpg","img/7.jpg"];var len=imgs.length;var index=0;$.preload(imgs,{});$("#control-img-btn").on("click","a",function(){ if($(this).hasClass("prevImg")){index=Math.max(0,--index); //上一张}else{index=Math.min(len-1,++index);//下一张}$("#imgBox img").attr("src",imgs[index]);});});

上一页 下一页

微信公众平台商城源码,vscode 接口测试插件,ubuntu集成网卡,tomcat重启不生效,wmts爬虫,php error 捕获,宁波seo在线优化方案,游戏开源网站源码下载,在线课程模板下载lzw

jQuery对象与原生DOM对象之间的区别及转换

js对象是什么?js对象类型有哪些?js对象类型的总结

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。