CSS100Day(24)-一个按钮动画
625 字
3 分钟
CSS100Day(24)-一个按钮动画
设计简介
关键点如下
-
知识点1:使用svg的
dasharray需要知道期望的周长,然后设置实线和虚线 -
知识点2:注意使用动画时候,利用动画时间和延迟事件来完成整个动画
效果展示
实现代码和步骤
HTML部分
<div class="frame"> <input type="checkbox" id="button" class="hidden" /> <label for="button" class="button"> Finish <img src="https://100dayscss.com/codepen/checkmark-green.svg" /> </label> <svg class="circle"> <circle cx="30" cy="30" r="29" /> </svg></div>CSS部分
.frame { width: 400px; height: 400px; color: #fff; background: #57d895; box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3); position: relative;}
.hidden { display: none;}
.button { position: absolute; box-sizing: border-box; display: block; width: 260px; height: 60px; top: 170px; left: 70px; border-radius: 30px; border: 2px solid #fff; text-align: center; line-height: 56px; font-size: 20px; font-weight: 700; letter-spacing: 2px; cursor: pointer; text-transform: uppercase; transition: all 0.3s ease-in-out;
&:hover { background: #37be77; }
img { position: absolute; top: 16px; left: 15px; opacity: 0; z-index: 2; }}
.circle { position: absolute; width: 60px; height: 60px; z-index: 2; top: 170px; left: 170px; fill: none; stroke: #fff; stroke-width: 2px; stroke-linecap: round; stroke-dasharray: 183 183; stroke-dashoffset: 183; pointer-events: none; transform: rotate(-90deg);}
input:checked { & ~ .button { animation: button 0.5s ease both, fill 0.5s ease-out 1.5s forwards;
img { animation: check 0.5s ease-out 1.5s both; } }
& ~ .circle { animation: circle 2s ease-out 0.5s both; }}
@keyframes button { 0% { width: 260px; left: 70px; border-color: #fff; color: #fff; } 50% { color: transparent; } 100% { width: 60px; left: 170px; border-color: #45b078; background: transparent; color: transparent; }}
@keyframes fill { 0% { background: transparent; border-color: #fff; } 100% { background: #fff; }}
@keyframes check { 0% { opacity: 0; } 100% { opacity: 1; }}
@keyframes circle { 0% { stroke-dashoffset: 183; } 50% { stroke-dashoffset: 0; stroke-dasharray: 183; opacity: 1; transform: rotate(-90deg) scale(1); } 100% { opacity: 0; transform: rotate(-90deg) scale(2); stroke-dashoffset: 0; }}分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
CSS100Day(2)-菜单按钮动画
设计灵感 菜单按钮都见过,但是三根条动画实现,关键利用no-animation初始化时候关闭回复动画
2
CSS100Day(28)-振铃动画
设计灵感 振铃动画
3
CSS100Day(23)-动态字体动画设计
设计灵感 线段的动画设计,以及文字隐藏出现的设计
4
CSS100Day(10)-SVG旋转动画
设计灵感 巧妙应用SVG的
5
CSS100Day(25)-翻转动画另一种实现
设计灵感 翻转动画另一种实现
随机文章
随机推荐