svg+css 或者js制作打鉤的動畫效果
發(fā)布時間:2020-03-31 15:33:10 作者:Published
我要評論
這篇文章主要介紹了svg+css 或者js制作打鉤的動畫效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
之前老板讓做一個登陸后 可以顯示一個打鉤的效果 百度死活搜不到 今天在B站看到的一個視頻居然有 根據(jù)需求改進了一下廢話不多說先看效果!

html代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>打鉤動畫</title>
</head>
<body>
<div id="d1">
<input type="checkbox" style="display: none" id="love1" />
<label for="love1" id="btn1" >完成</label>
<svg width="200px" height="200px">
<circle r="90" class="circle" fill="none" stroke="#2de540" stroke-width="10" cx="100" cy="100" stroke-linecap="round" transform="rotate(-90 100 100) " ></circle>
<polyline fill="none" stroke="#2de540" stroke-width="10" points="44,107 86,137 152,69" stroke-linecap="round" stroke-linejoin="round" class="tick" ></polyline>
</svg>
<h2 style="text-align: center;width: 200px">成功</h2>
</div>
</body>
<!--這里引入你本地的jq-->
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</html>
css代碼
h2 {
font-family: Helvetica;
font-size: 30px;
margin-top: 20px;
color: #333;
opacity: 0;
}
input[type="checkbox"]:checked+ label ~ h2 {
animation: .6s title ease-in-out;
animation-delay: 1.2s;
animation-fill-mode: forwards;
}
.circle {
stroke-dasharray: 1194;
stroke-dashoffset: 1194;
}
input[type="checkbox"]:checked + label + svg .circle {
animation: circle 1s ease-in-out;
animation-fill-mode: forwards;
}
.tick {
stroke-dasharray: 350;
stroke-dashoffset: 350;
}
input[type="checkbox"]:checked + label+ svg .tick {
animation: tick .8s ease-out;
animation-fill-mode: forwards;
animation-delay: .95s;
}
@keyframes circle {
from {
stroke-dashoffset: 1194;
}
to {
stroke-dashoffset: 2388;
}
}
@keyframes tick {
from {
stroke-dashoffset: 350;
}
to {
stroke-dashoffset: 0;
}
}
@keyframes title {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
label {
display: inline-block;
height: 38px;
width: 38px;
line-height: 38px;
padding: 0 18px;
background-color: #1E9FFF;
color: #fff;
white-space: nowrap;
text-align: center;
font-size: 14px;
border: none;
border-radius: 2px;
cursor: pointer;
}
#d1 {
display: flex;
justify-content: center;
min-height: 100px;
flex-direction: column;
}
寫到這里本來應(yīng)該就結(jié)束了 但是我們在真正實現(xiàn)功能的時候 不太可能用 checkbox切換動畫效果的顯示 一般還是需要按鈕操作動畫效果 下面是jq操作的代碼 其實用jq的.animate()更好一些但是我是小白所以就偷了個懶 (ps:好吧其實是不會)直接用.css()
JavaScript代碼
$("#btn1").on("click",function () {
if($(this).text()==="完成"){
$(".circle").css({'animation':'circle 1s ease-in-out','animation-fill-mode':'forwards'});
$(".tick").css({'animation':'tick .8s ease-out','animation-fill-mode':'forwards','animation-delay':'.95s'});
$("h2").css({'animation':'.6s title ease-in-out','animation-fill-mode':'forwards','animation-delay':'1.2s'})
$(this).text("取消")
}else{
$(".circle").css({'animation':'none','animation-fill-mode':'none'});
$(".tick").css({'animation':'none','animation-fill-mode':'none'});
$("h2").css({'animation':'none','animation-fill-mode':'none'})
$(this).text("完成")
}
});
到此這篇關(guān)于svg+css 或者js制作打鉤的動畫效果的文章就介紹到這了,更多相關(guān)svg css 打鉤動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
- 本文通過實例代碼給大家介紹了基于 CSS 動畫的 SVG 按鈕的實現(xiàn)方法,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2018-10-12

CSS使用SVG實現(xiàn)動態(tài)分布的圓環(huán)發(fā)散路徑動畫
這篇文章主要介紹了CSS使用SVG實現(xiàn)動態(tài)分布的圓環(huán)發(fā)散路徑動畫,第一時間看到這個需求想到的就是 SVG 或者 Canvas,但是由于開發(fā)時可能還需要插入其他元素,所以這里還是希2022-10-27


