本文實例為大家分享了js實現(xiàn)瀑布流圖片效果的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } #wrap{ position: relative; list-style: none; margin: 0 auto; } #wrap li{ width: 200px; font-size: 1.5rem; position: absolute; background-color: #CCCCCC; -webkit-transition: all 2s; } #wrap li div{ width: 100%; height: 100%; overflow: hidden; } </style> </head> <body> <ul id="wrap"></ul> </body> <script type="text/javascript" src="/upload/otherpic41/72925.html","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg"]; $("li").each(function(index, el) { var n = RandomNumBoth(0,imgArr.length-1); var imgsrc = imgArr[n]; $(this).html("<div><img onload='loadImage()' src='"+imgsrc+"'></div>"); }); }); function loadImage(){ $("img").each(function(index, el) { var a=$(this).width(), b=$(this).height(), pa = $(this).parent().width(), pb = $(this).parent().height(), e=a/b, //圖片寬高比 3 pe=pa/pb; //承載圖片容器寬高比 if(e>=pe){ $(this).css({height:"100%",width:"auto"}); var imgW = $(this).width(), iW = $(this).parent().width(), w = -(imgW - iW)/2; $(this).css('marginLeft',w); }else{ $(this).css({width:"100%",height:"auto"}); var imgH = $(this).height(), iH = $(this).parent().height(), h = -(imgH - iH)/2; $(this).css('marginTop',h); } }); } function RandomNumBoth(Min,Max){ var Range = Max - Min; var Rand = Math.random(); var num = Min + Math.round(Rand * Range); return num; } </script> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.rwnh.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章標(biāo)題:JavaScript實現(xiàn)瀑布流圖片效果-創(chuàng)新互聯(lián)
文章起源:http://www.rwnh.cn/article46/djhdhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、響應(yīng)式網(wǎng)站、微信公眾號、建站公司、域名注冊、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容