JavaScript實現(xiàn)瀑布流圖片效果-創(chuàng)新互聯(lián)

本文實例為大家分享了js實現(xiàn)瀑布流圖片效果的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)為您提適合企業(yè)的網(wǎng)站設計?讓您的網(wǎng)站在搜索引擎具有高度排名,讓您的網(wǎng)站具備超強的網(wǎng)絡競爭力!結合企業(yè)自身,進行網(wǎng)站設計及把握,最后結合企業(yè)文化和具體宗旨等,才能創(chuàng)作出一份性化解決方案。從網(wǎng)站策劃到網(wǎng)站設計制作、成都做網(wǎng)站, 我們的網(wǎng)頁設計師為您提供的解決方案。
<!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>

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站bm7419.com,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

文章標題:JavaScript實現(xiàn)瀑布流圖片效果-創(chuàng)新互聯(lián)
文章起源:http://bm7419.com/article46/djhdhg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、響應式網(wǎng)站微信公眾號、建站公司域名注冊、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設