好久没写动画了,最近公司在做红包营销,需要加点动画效果,所以就参照某夕夕的红包效果来一练一下手,其实代码很简单我就直接上代码了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.page-box {
margin: 0 auto;
width: 400px;
height: 500px;
transform-style: preserve-3d; // 子元素将保留其 3D 位置
perspective: 1000; // 视距设置
-webkit-perspective: 1000;
}
.main-box {
margin-top: 50px;
height: 40px;
width: 200px;
border-radius: 5px;
color: #333;
background-color: red;
text-align: center;
line-height: 40px;
animation-name: scaleAnimation; // 动画名
animation-duration: 2s; // 动画时长
animation-iteration-count: infinite; // 永久动画
transition-timing-function: ease-in-out; // 动画过渡
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); // 元素阴影
}
@keyframes scaleAnimation { // 动画设置
0% {
transform: scale(1);
}
25% {
transform: scale(1.08);
}
50% {
transform: scale(1);
}
75% {
transform: scale(1.08);
}
}
</style>
</head>
<body>
<div class="page-box">
<div class="main-box">领红包了</div>
</div>
</body>
</html>