手机版

JavaScript实现自动加载图片的瀑布效果

时间:2021-11-04 来源:互联网 编辑:宝哥软件园 浏览:

让我先给你看效果图:

当您向下滑动网页时,您可以自动加载图片并显示它们。

图片的盒子模型如下:

class=' box ' div class=' box_img ' img src=' http : img/8 . jpg '/div/div将img-width设置为150px,然后box _ img添加内边距和阴影效果,box的外边距为0,所以添加内边距。框的宽度由img-width和边距扩展。也就是说,盒子之间没有空间,但是盒子里面有一些边距。这样,js设置位置的时候,就不需要考虑边距问题了,直接调用box的宽度就可以了。

将包含所有框的div的位置设置为相对,这样在设置顶值或左值时,就不需要考虑最外面的边距属性。

放置图片的位置:获取第一行图片的高度并存储在数组中,将下一张图片的位置设置为绝对,将其放置在高度最小的图片下方,然后设置顶部和左侧,并将数组的最小值加到新放置图片的高度上。也就是说,除了第一行,原来放在HTML中的图片都在js中重新定位。

当页面滑动到底部时,触发事件功能,然后放置一些图片,这样可以保证图片的无限加载。

HTML文件:

!doctype html head lang=' meta charset=' utf-title/title line rel=' style sheet ' href=' water fall。CSS ' type=' text/CSS '脚本src=' http 3360落水。js '/script/head body div id=' content ' div class=' box _ img ' src=' http 3360 img/.jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div div class=' box ' div class=' box _ img ' img src=' http 3360 img/。jpg '/div/div/body/html CSS哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟:

* {利润3360;填色:} #内容{相对位置:背景色: #;}。盒子{填充:像素浮动3360左;}。box _ img {填充:像素边界:像素固体#cccccc盒影: px #cccccc边界半径: px} img {宽度:像素高度:辆汽车;}js哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟:

Math.floor()范仲淹?范仲淹。

数学最小应用程序(null、heightarr);范仲淹王高地人队。

window.onscroll=function(){}:我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊。

文件。文档元素。客户端高度:我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊!我的天啊。

文件。文档元素。滚动顶部;朱庇特朱庇特。

/***由阿苏亚于2016/4/9年创建*/window。onload=function(){ img位置(' content ',' box ');var lode imer={ ' date ' 3360[{ ' src ' 3360 ' 1。jpg ' },{ ' src ' : ' 2。jpg ' },{ ' src ' : ' 3。jpg ' },{ ' src ' : ' 4。jpg ' },{ ' src ' : ' 5。jpg ' },{ ' src ' : ' 6。jpg ' },{ ' src ' : ' 7。jpg ' },{ ' src ' : ' 8。jpg ' },{ ' src ' : ' 9。使用jpeg文件交换格式存储的编码图像文件扩展名伊洛米尔日期。长度(I){ var box=文档。创建元素(' div ');盒子。cparent=document .获取元素byid(' content ');cparent.appendChild(盒子);var box _ img=文档。创建元素(' div '):box _ img。box _ imgbox . appendchild(box _ img):var img=document .创建元素(' img '):img。src=' http 3360 img/' LOD图像.日期[i].src(人力资源管理厅);box _ img . appendchild(img):} imgLocation(' content ',' box ');}}函数检查标志(){ var cparent=document。获取元素byid(' content ');var cccontent=get子元素(cparent," box ");var lastcontentheight=ccnt content[ccnt nt。长度-1].offsettopvar滚动高度=文档。文档元素。向上滚动| |文档。尸体。滚动顶部;var pageheight=document。文档元素。客户端高度| |文档。尸体。客户身高;控制台。日志(lastcontentheight ' 3330 '滚动高度' 3330 '页面高度):if(lastcontentheight滚动高度页面高度){ 0返回真实语言函数(父代、子代){ var cparent=document。getelement byid(父代);var ccnt=获取子级元素(cparent,child);var img width=cccontent[0].偏移宽度;var cols=数学。楼层(文件。文档元素。客户端宽度/img宽度):cparent。风格。CSS text=' width 3360 ' img width * cols ' px;边际33330px汽车;var heightArr=[]:S7-1200可编程控制器:iccontent。长度(I){ if(icos){ heightarr。push(ccnt nt)[I]。右偏(偏移高度):} else { var my height=math。量滴应用(null,heightarr);var mini index=getmini index(height arr,minhAiR):ccnt[I]。风格。位置='绝对';我。风格。top=我的身高‘px’;我。风格。left=ccnt[mini index].offsetleft ' pxhx8arr[mini index]=cccontent[I].偏移高度;}}函数获取索引(高度arr,最小高度){ for(var I=0);我八岁了。长度(I){ if(heightarr[I]==最小高度){ return I;}}函数getChildElement(父,内容){ var content arr=[];var all content=parent。get element sbytname(' * ');S7-1200可编程控制器:艾勒库特。长度(一){ if(所有内容[I]).类名==content){ content arr。推送(所有内容[I]);} }返回contentarr}你好,云娥联署材料是吴登盛吗?是吴登盛吗?是吴登盛吗,吴亚玲吴亚玲!

版权声明:JavaScript实现自动加载图片的瀑布效果是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。