美文网首页前端
照片墙代码

照片墙代码

作者: wppeng | 来源:发表于2019-03-27 17:31 被阅读2次

html

<div id="datalist" class="container">
            
</div>

css

                        html,
            body {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                
            }
            body{
                display: flex;
                justify-content: center;
                align-items: center;
                background-color: #ddeaf0;
            }

            .container {
                
                width: 90%;
                height: 90%;
                position: relative;
                background-color: #ddeaf0;
            }

            .container img {
                width: 268px;
                height: auto;
                padding: 10px;
                background: white;
                border: 1px solid #ddd;
                box-shadow: 2px 2px 3px rgba(50, 50, 50, 0.4);
                -webkit-transition: all 0.5s ease-in;
                -moz-transition: all 0.5s ease-in;
                transition: all 0.5s ease-in;
                position: absolute;
                z-index: 1;
            }

            .container img:hover {
                box-shadow: 15px 15px 20px rgba(50, 50, 50, 0.4);
                -webkit-transform: rotate(0deg) scale(1.60);
                -moz-transform: rotate(0deg) scale(1.60);
                transform: rotate(0deg) scale(1.60);
                z-index: 2;
            }
            
            .pic{
                -webkit-transform: rotate(-5deg);
                -moz-transform: rotate(-5deg);
                transform: rotate(-5deg);
            }

js

                var clientWidth= document.body.clientWidth;
        var clientHeight=document.body.clientHeight;
        //console.log('浏览器高'+clientHeight);
        //console.log('浏览器宽'+clientWidth);
        var maxNumber=0;
        if(clientHeight>clientWidth){
            maxNumber=clientWidth;
        }else{
            maxNumber=clientHeight;
        }
        maxNumber=Math.floor(maxNumber/2);
        var a=[1,maxNumber];
        //console.log(a);
        var data=['image/1.jpg','image/2.jpg','image/3.jpg','image/4.jpg','image/5.jpg'];
        //console.log(randomNumber(...a));
        var htmlShow='';
        var htmllist=[];
        for(var index in data){
            console.log(data[index]);
            htmllist.push('<img class="pic" style="top:'+randomNumber(...a)+'px;bottom:'+randomNumber(...a)+'px;left:'+randomNumber(...a)+'px;right:'+randomNumber(...a)+'px;"  src="'+data[index]+'">')
        }
        htmlShow=htmllist.join('');
        //htmlShow='';
        document.getElementById('datalist').innerHTML=htmlShow;
        /**
         * min:随机数下限
         * max:随机数上限
         */
        function randomNumber(min,max){
            return Math.floor(Math.random()*(max-min+1)+min);
        }

整个页面

<!DOCTYPE html>
<html>
    <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta charset="utf-8">
        <title>照片墙</title>
        <style>
            html,
            body {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                
            }
            body{
                display: flex;
                justify-content: center;
                align-items: center;
                background-color: #ddeaf0;
            }

            .container {
                
                width: 90%;
                height: 90%;
                position: relative;
                background-color: #ddeaf0;
            }

            .container img {
                width: 268px;
                height: auto;
                padding: 10px;
                background: white;
                border: 1px solid #ddd;
                box-shadow: 2px 2px 3px rgba(50, 50, 50, 0.4);
                -webkit-transition: all 0.5s ease-in;
                -moz-transition: all 0.5s ease-in;
                transition: all 0.5s ease-in;
                position: absolute;
                z-index: 1;
            }

            .container img:hover {
                box-shadow: 15px 15px 20px rgba(50, 50, 50, 0.4);
                -webkit-transform: rotate(0deg) scale(1.60);
                -moz-transform: rotate(0deg) scale(1.60);
                transform: rotate(0deg) scale(1.60);
                z-index: 2;
            }
            
            .pic{
                -webkit-transform: rotate(-5deg);
                -moz-transform: rotate(-5deg);
                transform: rotate(-5deg);
            }
        </style>
    </head>
    <body>
        <div id="datalist" class="container">
            
        </div>
    </body>
    <script>
        var clientWidth= document.body.clientWidth;
        var clientHeight=document.body.clientHeight;
        //console.log('浏览器高'+clientHeight);
        //console.log('浏览器宽'+clientWidth);
        
        var maxNumberH=Math.floor(clientHeight/2);
        var maxNumberW=Math.floor(clientWidth-400);
        var H=[1,maxNumberH];
        var W=[1,maxNumberW];
        //console.log(a);
        var data=['image/1.jpg','image/2.jpg','image/3.jpg','image/4.jpg','image/5.jpg'];
        //console.log(randomNumber(...a));
        var htmlShow='';
        var htmllist=[];
        for(var index in data){
            console.log(data[index]);
            htmllist.push('<img class="pic" style="top:'+randomNumber(...H)+'px;bottom:'+randomNumber(...H)+'px;left:'+randomNumber(...W)+'px;right:'+randomNumber(...W)+'px;"  src="'+data[index]+'">')
        }
        htmlShow=htmllist.join('');
        //htmlShow='';
        document.getElementById('datalist').innerHTML=htmlShow;
        /**
         * min:随机数下限
         * max:随机数上限
         */
        function randomNumber(min,max){
            return Math.floor(Math.random()*(max-min+1)+min);
        }
        
    </script>
</html>


相关文章

  • 2018-11-01

    照片墙 html代码 照片墙 开始 css代码*{padding: ...

  • 照片墙代码

    html css js 整个页面

  • python:照片墙设计,将照片布局成爱心形状~

    python照片墙设计 代码规划: 将爬虫爬取的图片进行处理,减小尺寸 将处理好的图片进行照片墙设计 图片处理Im...

  • 照片墙

    【美印定制~九宫格照片墙】照片墙,可以放九张图片,时下最流行的墙上挂件想怎么摆就怎么摆,好看又有意义,️重要的价位...

  • 照片墙

    生活的点滴从拍照的哪一刻起……

  • 照片墙

  • 照片墙

    我一直想拥有一面属于自已的照片墙,以前旧房子潮湿,墙面粗燥,一大家子居住,二位老人年纪大,家中杂物又多,根本不适合...

  • 照片墙

    从6.5号到6.10号,混混厄厄的。印象最深的大抵就是职工餐厅那锅很带感的虾尾了。只可惜当时只顾着吃去了。 ...

  • 照片墙

    闲来无事,自己写了一个照片墙,效果还凑合.大家喜欢的话可以自己学习一下制作属于自己的照片墙.首先先创建一个文件夹为...

  • 照片墙

    一直说的把照片墙弄了,今天终于完成了这个任务,虽然结果有点打折,但是我很喜欢夫妻同心,一起思考,读懂彼此想法,一起...

网友评论

    本文标题:照片墙代码

    本文链接:https://www.haomeiwen.com/subject/laktbqtx.html