JavaScript实现瀑布流图片效果-创新互联

本文实例为大家分享了js实现瀑布流图片效果的具体代码,供大家参考,具体内容如下

创新互联为您提适合企业的网站设计 让您的网站在搜索引擎具有高度排名,让您的网站具备超强的网络竞争力!结合企业自身,进行网站设计及把握,最后结合企业文化和具体宗旨等,才能创作出一份性化解决方案。从网站策划到网站设计制作、成都做网站, 我们的网页设计师为您提供的解决方案。
<!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>

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

文章标题:JavaScript实现瀑布流图片效果-创新互联
文章起源:https://www.cdcxhl.com/article46/djhdhg.html

成都网站建设公司_创新互联,为您提供商城网站响应式网站微信公众号建站公司域名注册做网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设