CSS100Day(16)-利用before、after伪元素完成长方形散花动画
1391 字
7 分钟
CSS100Day(16)-利用before、after伪元素完成长方形散花动画
设计简介
本次主要利用两个关键点:
-
知识点1:一个是全局统一动画时长5s,然后使用0%、32%、74%等各自元素控制自己的出现和消失
-
知识点2:after和before可以实现长条形,父元素为一个长条背景颜色transparent,而after、before有颜色,这就像金箍棒的两端
效果展示
实现代码和步骤
HTML部分
HTML部分如下
<div class="frame"> <div class="blobb"></div> <div class="blobb-ring"></div> <svg class="octagon"> <polygon points="30,0 70,0 100,30 100,70 70,100 30,100 0,70 0,30" /> </svg> <svg class="triangle"> <polygon points="53,0 106,90 0,90" /> </svg> <div class="octa-sparkles"> <div class="sparkle s1"></div> <div class="sparkle s2"></div> <div class="sparkle s3"></div> <div class="sparkle s4"></div> </div> <div class="triangle-sparkles"> <div class="sparkle s1"></div> <div class="sparkle s2"></div> <div class="sparkle s3"></div> </div></div>CSS部分
注意2知识点即可
.frame { width: 400px; height: 400px; border-radius: 2px; box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3); background: #46a6da; position: relative; overflow: hidden;}
.blobb { position: absolute; width: 90px; height: 90px; top: 155px; left: 155px; background: #fff; border-radius: 50%; animation: blobby 5s ease-in-out infinite;}
.blobb-ring { position: absolute; box-sizing: border-box; width: 110px; height: 110px; top: 145px; left: 145px; border: 3px solid #fff; border-radius: 50%; animation: blobby-ring 5s ease-in-out infinite;}
.octagon { position: absolute; width: 100px; height: 100px; top: 150px; left: 150px; fill: #fff; animation: octa 5s ease-in-out infinite;}
.octa-sparkles { position: absolute; width: 200px; height: 200px; top: 100px; left: 100px; animation: octa-sparkle 5s ease-in-out infinite;
.sparkle { position: absolute; top: 0; left: 98px; width: 4px; height: 200px;
&:before, &:after { display: block; content: ""; position: absolute; width: 4px; height: 25px; top: 0; left: 0; border-radius: 2px; background: #fff; }
&:after { top: auto; bottom: 0; } }
.s2 { transform: rotate(45deg); } .s3 { transform: rotate(90deg); } .s4 { transform: rotate(135deg); }}
.triangle { position: absolute; width: 106px; height: 90px; top: 145px; left: 147px; fill: #fff; animation: triangle 5s ease-in-out infinite;}
.triangle-sparkles { position: absolute; width: 200px; height: 200px; top: 100px; left: 100px; animation: triangle-sparkle 5s ease-in-out infinite;
.sparkle { position: absolute; top: 0; left: 98px; width: 4px; height: 200px;
&::before, &::after { position: absolute; display: block; content: ""; width: 4px; height: 25px; border-radius: 2px; background-color: #fff; top: 0; left: 0; } }
.s1 { top: 10px; } .s2 { rotate: 124deg; } .s3 { rotate: 237deg; }}
/* 前面1s,后面1s,中间消失3秒 */@keyframes blobby { 0% { transform: translate3d(0, -300px, 0) scaleY(1.2); } 10% { transform: translate3d(0, 50px, 0) scaleY(0.8); } 14% { transform: translate3d(0, -30px, 0) scaleY(1.1); } 18% { transform: translate3d(0, 10px, 0) scaleY(0.9); } 20%, 22% { transform: translate3d(0, 0, 0) scaleY(1); } 26% { transform: translate3d(0, 0, 0) scale(1.2); } 32%, 74% { transform: translate3d(0, 0, 0) scale(0); } 80% { transform: translate3d(0, 0, 0) scale(1.2); } 84% { transform: translate3d(0, 0, 0) scale(0.9); } 86%, 88% { transform: translate3d(0, 0, 0) scale(1); } 92% { transform: translate3d(0, -30px, 0) scaleY(0.9); } 100% { transform: translate3d(0, 300px, 0) scaleY(1.2); }}
@keyframes blobby-ring { 0%, 74% { transform: translate3d(0, 0, 0) scale(0); opacity: 1; } 80% { opacity: 1; } 84%, 100% { transform: translate3d(0, 0, 0) scale(1.4); opacity: 0; }}
@keyframes octa { 0%, 30% { transform: translate3d(0, 0, 0) scale(0) rotate(22.5deg); } 36% { transform: translate3d(0, 0, 0) scale(1.2) rotate(22.5deg); } 40% { transform: translate3d(0, 0, 0) scale(0.9) rotate(22.5deg); } 42%, 44% { transform: translate3d(0, 0, 0) scale(1) rotate(22.5deg); } 48% { transform: translate3d(0, 0, 0) scale(1.2) rotate(22.5deg); } 54%, 100% { transform: translate3d(0, 0, 0) scale(0) rotate(22.5deg); }}
@keyframes triangle { 0%, 52% { transform: translate3d(0, 0, 0) scale(0); } 58% { transform: translate3d(0, 0, 0) scale(1.2); } 62% { transform: translate3d(0, 0, 0) scale(0.9); } 64%, 66% { transform: translate3d(0, 0, 0) scale(1); } 70% { transform: translate3d(0, 0, 0) scale(1.2); } 76%, 100% { transform: translate3d(0, 0, 0) scale(0); }}
@keyframes octa-sparkle { 0%, 30% { transform: translate3d(0, 0, 0) scale(0); opacity: 1; } 36% { opacity: 1; } 40%, 100% { transform: translate3d(0, 0, 0) scale(1.4); opacity: 0; }}
@keyframes triangle-sparkle { 0%, 52% { transform: translate3d(0, 0, 0) scale(0); opacity: 1; } 58% { opacity: 1; } 62%, 100% { transform: translate3d(0, 0, 0) scale(1.4); opacity: 0; }}分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
CSS100Day(21)-利用svg线段实现吃小球动画
设计灵感 利用svg线段实现吃小球动画
2
CSS100Day(18)-3D实现弹性元素
设计灵感 3D实现弹性元素
3
CSS100Day(4)-利用关键帧三圆嵌套动画
设计灵感 一个训练keyframe的练习,利用box-shadow造成嵌套感觉
4
CSS100Day(10)-SVG旋转动画
设计灵感 巧妙应用SVG的
5
CSS100Day(20)-发送邮件惊艳动画无JS
设计灵感 纯css实现发送邮件,利用checkbox
随机文章
随机推荐