3D旋转照片墙

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>photo</title>
    </head>
    <style>
        #imgWrap{
            width: 550px;
            height: 450px;
            margin: 0 auto;
            perspective: 550px;
        }
        img{
            float: left;
            width: 80px;
            height: 80px;
        }
        #btn{
            width: 100px;
            text-align: center;
            font:16px/40px "微软雅黑";
            color: #fff;
            padding: 0 20px;
            background: rgb(0,100,0);
            margin: 0 auto;
            border-radius: 5px;
            box-shadow: 2px 2px 5px rgba(0,0,0,0.5);
            margin: 0 auto;
            cursor: pointer;
        }
    </style>
    <body>
        <div id="imgWrap">
            <img src="img/1.jpg" alt="" />
            <img src="img/2.jpg" alt="" />
            <img src="img/3.jpg" alt="" />
            <img src="img/4.jpg" alt="" />
            <img src="img/5.jpg" alt="" />
            <img src="img/6.jpg" alt="" />
            <img src="img/7.jpg" alt="" />
            <img src="img/8.jpg" alt="" />
            <img src="img/9.jpg" alt="" />
            <img src="img/10.jpg" alt="" />
            <img src="img/11.jpg" alt="" />
            <img src="img/12.jpg" alt="" />
            <img src="img/13.jpg" alt="" />
            <img src="img/14.jpg" alt="" />
            <img src="img/15.jpg" alt="" />
            <img src="img/16.jpg" alt="" />
            <img src="img/17.jpg" alt="" />
            <img src="img/18.jpg" alt="" />
            <img src="img/19.jpg" alt="" />
            <img src="img/20.jpg" alt="" />
            <img src="img/21.jpg" alt="" />
            <img src="img/22.jpg" alt="" />
            <img src="img/23.jpg" alt="" />
            <img src="img/24.jpg" alt="" />
            <img src="img/25.jpg" alt="" />
            <img src="img/26.jpg" alt="" />
            <img src="img/27.jpg" alt="" />
            <img src="img/28.jpg" alt="" />
            <img src="img/29.jpg" alt="" />
            <img src="img/30.jpg" alt="" />
        </div>
        <div id="btn">
            显示效果
        </div>
    </body>
    <script>
        window.οnlοad=function(){
            var btn=document.getElementById("btn");
            var imgs=document.querySelectorAll("img");
            var on = true;
            
            //给btn添加点击事件
            btn.οnclick=function(){
                if(!on){
                    return;
                }
                on=false;
                var endNum=0;
                var allEnd=0;
                for (var i=0;i<imgs.length;i++) {
                    (function(i){
                         setTimeout(function(){
                      montion(imgs[i],'1s',function(){
                        this.style.transform='scale(0)';
                    },function(){
                        montion(this,'1s',function(){
                                this.style.transform='scale(1)';
                                this.style.opacity=0;
                        },function(){
                            endNum++;
                            if(endNum==imgs.length){
                                toBig();
                            }  
                        });
                        
                    });
                  },Math.random()*1000);//随机变化
                    })(i)
                }    
                function toBig(){
                for (var i=0;i<imgs.length;i++) {
                    imgs[i].style.transition='';
                    imgs[i].style.transform='rotateY(0deg) translateZ(-'+Math.random()*500+'px)';
                    
                    (function(i){
                        setTimeout(function(){
                            montion(imgs[i],'2s',function(){
                                this.style.opacity=1;
                                this.style.transform='rotateY(-360deg) translateZ(0)';
                            },function(){
                                allEnd++;
                                if(allEnd==imgs.length){
                                on=true;    
                                }
                            });
                        },Math.random()*1000);
                    })(i);
                }
            }
            };

        //运动函数(运动的对象,运动的时间,运动的属性函数,运动完要做的事情)
            function montion(obj,time,doFn,callBack){
                obj.style.transition=time;
                doFn.call(obj);
                
                var called=false;
                
                obj.addEventListener('transitionend',function(){
                    if(!called){
                        callBack&&
                     callBack.call(obj);
                        called=true;
                    }
                    
                },false);
            }
        };
    </script>
</html>

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值