本文实例为大家讲解了javascript瀑布流代码,即js页面滚动延迟加载图片,分享给大家供大家参考,具体代码如下
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>原生Js页面滚动延迟加载图片</title> <style type="text/css"> * { margin:0; padding:0 } img.scrollLoading { border:1px solid #ccc; display:block; margin-top:10px; } </style> </head> <body> <div id="content"></div> </body> </html> <script type="text/javascript"> var _CalF = { $:function(object){//选择器 if(object === undefined ) return; var getArr = function(name,tagName,attr){ var tagName = tagName || '*', eles = document.getElementsByTagName(tagName), clas = (typeof document.body.style.maxHeight === "undefined") "className" : "class";//ie6 attr = attr || clas, Arr = []; for(var i=0;i<eles.length;i++){ if(eles[i].getAttribute(attr)==name){ Arr.push(eles[i]); } } return Arr; }; if(object.indexOf('#') === 0){ //#id return document.getElementById(object.substring(1)); } else if(object.indexOf('.') === 0){ //.class return getArr(object.substring(1)); } else if(object.match(/=/g)){ //attr=name return getArr(object.substring(object.search(/=/g)+1),null,object.substring(0,object.search(/=/g))); } else if(object.match(/./g)){ //tagName.className return getArr(object.split('.')[1],object.split('.')[0]); } }, getPosition : function(obj) { //获取元素在页面里的位置和宽高 var top = 0, left = 0, width = obj.offsetWidth, height = obj.offsetHeight; while(obj.offsetParent){ top += obj.offsetTop; left += obj.offsetLeft; obj = obj.offsetParent; } return {"top":top,"left":left,"width":width,"height":height}; } }; //添加图片list var _temp = []; for (var i = 1; i < 21; i ++) { _temp.push('<img class="scrollLoading" data-src="/UploadFiles/2021-04-02/o_' + i + '.jpg">希望本文所述对大家学习javascript程序设计有所帮助。
标签:
js,加载图片
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“原生js页面滚动延迟加载图片”评论...