css3 徽章特效
实现
使用N张图片,使其在Z轴偏移堆叠,形成厚度,使用3D转换,就是徽章的效果了
代码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body{
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
@keyframes spin {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(360deg);
}
}
.badge {
width: 23vw;
height: 23vw;
min-width: 400px;
min-height: 400px;
transform-style: preserve-3d;
animation: spin 5.5s linear infinite;
}
.badge > div:nth-child(1) {
transform: translateZ(0.5px);
}
.badge > div:nth-child(2) {
transform: translateZ(1px);
}
.badge > div:nth-child(3) {
transform: translateZ(1.5px);
}
.badge > div:nth-child(4) {
transform: translateZ(2px);
}
.badge > div:nth-child(5) {
transform: translateZ(2.5px);
}
.badge > div:nth-child(6) {
transform: translateZ(3px);
}
.badge > div:nth-child(7) {
transform: translateZ(3.5px);
}
.badge > div:nth-child(8) {
transform: translateZ(4px);
}
.badge > div:nth-child(9) {
transform: translateZ(4.5px);
}
.badge > div:nth-child(10) {
transform: translateZ(5px);
}
.badge > div:nth-child(11) {
transform: translateZ(5.5px);
}
.badge > div:nth-child(12) {
transform: translateZ(6px);
}
.badge > div:nth-child(13) {
transform: translateZ(6.5px);
}
.badge > div:nth-child(14) {
transform: translateZ(7px);
}
.badge > div:nth-child(15) {
transform: translateZ(7.5px);
}
.badge > div:nth-child(16) {
transform: translateZ(8px);
}
.badge > div:nth-child(17) {
transform: translateZ(8.5px);
}
.badge > div:nth-child(18) {
transform: translateZ(9px);
}
.badge > div:nth-child(19) {
transform: translateZ(9.5px);
}
.badge > div:nth-child(20) {
transform: translateZ(10px);
}
.badge > div {
background-image: url("https://web03-1252477692.cos.ap-guangzhou.myqcloud.com/blog/images/1e84e715773a4652a0207d7e501341a1.png");
height: 100%;
width: 100%;
transform: translateZ(1px);
position: absolute;
top: 0;
background-size: 100% 100%;
}
</style>
</head>
<body>
<div class="badge">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>