Tick animation produced by svg + css or js

Before boss asked to make a landing can be displayed after a tick effect Baidu search less than life and death today in B station saw a video actually improved a little nonsense look at the effect on demand will not say!

 

html code

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>打钩动画</title>
 6 </head>
 7 <body>
 8 <div id="d1">
 9     <input type="checkbox" style="display: none" id="love1" />
10     <label for="love1" id="btn1" >完成</label>
11 <svg width="200px" height="200px">
12     <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>
13     <polyline  fill="none" stroke="#2de540" stroke-width="10" points="44,107 86,137 152,69" stroke-linecap="round" stroke-linejoin="round" class="tick" ></polyline>
14 </svg>
15 <h2 style="text-align: center;width: 200px">成功</h2>
16 
17 </div>
18 </body>
20->here to introduce your local JQ<! -19 
 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
21 </html>

css code

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;
    }

I write to you should have ended, but we are unlikely to show a checkbox to switch animation in real time function button operation requires general or animation Here is the code jq actually operated by .animate jq of () better but I was white so I stole a lazy (ps: Well, in fact, is not) directly .css ()

JavaScript code

   $("#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("Cancel " 
           $ ({the 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("完成")
       }
   });

 Oh yeah, and one more thing to remember to give people a primary UP key triple (BV1ME411F7BG)

Guess you like

Origin www.cnblogs.com/milletHandsome/p/12601596.html