我正在参加「创意开发 投稿大赛」详情请看:掘金创意开发大赛来了!
相册魔方
闲来无事做了个相册魔方,留下和他/她的回忆。
- 前端接触较少,但是有些基础,于是也喜欢做一些小玩意玩玩。
- 非常简单只需替换图片地址即可。
- 使用码上掘金生成代码块
HTML
大正方形
添加几个块元素,并在块元素中插入图片。
<div class="box">
<div class="bigfront">
<img src="http://pic.rmb.bdstatic.com/bjh/beautify/254544ba325295fe46e222a61934a374.jpeg@c_1,w_424,h_283,x_0,y_0" class="bigpic" >
</div>
<div class="bigback">
<img src="https://img0.baidu.com/it/u=871152699,1570153357&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=675" class="bigpic">
</div>
<div class="bigleft">
<img src="https://img2.baidu.com/it/u=2468362699,2612376962&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" class="bigpic">
</div>
<div class="bigright">
<img src="https://img0.baidu.com/it/u=1340408184,1681650826&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=750" class="bigpic">
</div>
<div class="bigtop">
<img src="https://img0.baidu.com/it/u=2800906937,536160671&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" class="bigpic">
</div>
<div class="bigbottom">
<img src="https://img1.baidu.com/it/u=1486625970,4005600526&fm=253&fmt=auto&app=138&f=JPEG?w=346&h=500" class="bigpic">
</div>
复制代码
小正方形
添加几个内联级元素,并插入图片。
<span class="smallfront">
<img src="https://img2.baidu.com/it/u=1595173768,2923508947&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800" class="smallpic" />
</span>
<span class="smallback">
<img src="https://img2.baidu.com/it/u=2438645924,3546232272&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" class="smallpic" />
</span>
<span class="smallleft">
<img src="https://img1.baidu.com/it/u=359599488,1153127555&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500" class="smallpic" />
</span>
<span class="smallright">
<img src="https://img0.baidu.com/it/u=4190953476,3527458401&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=1081" class="smallpic" />
</span>
<span class="smalltop">
<img src="https://img1.baidu.com/it/u=1364770270,3685425439&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" class="smallpic" />
</span>
<span class="smallbottom">
<img src="https://img0.baidu.com/it/u=1049447290,3608866120&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=625" class="smallpic" />
</span>
复制代码
预想效果:
本来插入的是本地图片,不过码上掘金未生效就找了几张网上图片来演示效果。
css样式
背景颜色也可以改为图片!
html{
width: 100%;
height: 100%;
}
body{
background-color: hsl(0, 0%, 0%);
margin: 0;
padding: 0;
}
.bigbox{
width: 10px;
height: 10px;
margin: 200px 400px;
position: relative;
}
复制代码
添加过渡动画
.box{
width:500px;
height:300px;
margin: 0 auto;
transform-style: preserve-3d;
transform: rotateX(-30deg) rotateY(-80deg);
-webkit-animation: mystyle 20s infinite;
animation: mystyle 20s infinite;
animation-timing-function: linear;
}
@keyframes mystyle{
from{transform: rotateX(-180deg) rotateY(-180deg);}
to{transform: rotateX(180deg) rotateY(180deg);}
}
复制代码
大正方形样式
.box div{
position: absolute;
width: 200px;
height: 200px;
opacity: 0.8;
transition: all .4s;
}
.bigpic{
width: 200px;
height: 200px;
}
.box .bigfront{
transform: rotateY(0deg) translateZ(100px);
}
.box .bigback{
transform: translateZ(-100px) rotateY(180deg);
}
.box .bigleft{
transform: rotateY(90deg) translateZ(100px);
}
.box .bigright{
transform: rotateY(-90deg) translateZ(100px);
}
.box .bigtop{
transform: rotateX(90deg) translateZ(100px);
}
.box .bigbottom{
transform: rotateX(-90deg) translateZ(100px);
}
复制代码
小正方形样式
.box span{
display: block;
position: absolute;
width: 140px;
height: 140px;
top: 25px;
left: 25px;
}
.box .smallpic{
width: 140px;
height: 140px;
}
.box .smallleft{
transform: rotateY(90deg) translateZ(70px);
}
.box .smallright{
transform: rotateY(-90deg) translateZ(70px);
}
.box .smalltop{
transform: rotateX(90deg) translateZ(70px);
}
.box .smallbottom{
transform: rotateX(-90deg) translateZ(70px);
}
.box .smallfront{
transform: rotateY(0deg) translateZ(70px);
}
.box .smallback{
transform: translateZ(-70px) rotateY(180deg);
}
复制代码
大正方形散开样式
- hover 一个css选择器,能够让鼠标指向的时候触发
- 这里只让大正方形散开
.box:hover .bigleft{
transform: rotateY(90deg) translateZ(300px);
}
.box:hover .bigright{
transform: rotateY(-90deg) translateZ(300px);
}
.box:hover .bigtop{
transform: rotateX(90deg) translateZ(300px);
}
.box:hover .bigbottom{
transform: rotateX(-90deg) translateZ(300px);
}
.box:hover .bigfront{
transform: rotateY(0deg) translateZ(300px);
}
.box:hover .bigback{
transform: translateZ(-300px) rotateY(180deg);
}
复制代码