您好,登錄后才能下訂單哦!
這篇文章主要介紹了svg+css或者js怎么制作打鉤的動(dòng)畫(huà)效果,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
效果圖:
html代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>打鉤動(dòng)畫(huà)</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> <h3 style="text-align: center;width: 200px">成功</h3> </div> </body> <!--這里引入你本地的jq--> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> </html>
css代碼
h3 { font-family: Helvetica; font-size: 30px; margin-top: 20px; color: #333; opacity: 0; } input[type="checkbox"]:checked+ label ~ h3 { 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; }
寫(xiě)到這里本來(lái)應(yīng)該就結(jié)束了 但是我們?cè)谡嬲龑?shí)現(xiàn)功能的時(shí)候 不太可能用 checkbox切換動(dòng)畫(huà)效果的顯示 一般還是需要按鈕操作動(dòng)畫(huà)效果 下面是jq操作的代碼 其實(shí)用jq的.animate()更好一些但是我是小白所以就偷了個(gè)懶 (ps:好吧其實(shí)是不會(huì))直接用.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'}); $("h3").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'}); $("h3").css({'animation':'none','animation-fill-mode':'none'}) $(this).text("完成") } });
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“svg+css或者js怎么制作打鉤的動(dòng)畫(huà)效果”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。