久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SVG實(shí)現(xiàn)多彩圓環(huán)倒計(jì)時(shí)效果的示例代碼

這篇文章主要介紹了SVG實(shí)現(xiàn)多彩圓環(huán)倒計(jì)時(shí)效果的示例代碼,本文主要用到了SVG的stroke-dasharray和stroke-dashoffset特性 ,具有一定的參考價(jià)值,有興趣的可以了解一下

圓環(huán)倒計(jì)時(shí)我們經(jīng)常見到,實(shí)現(xiàn)的方法也有很多種。但是本文將介紹一種全新的實(shí)現(xiàn)方式,使用SVG來實(shí)現(xiàn)倒計(jì)時(shí)功能。

本文主要用到了SVG的stroke-dasharray和stroke-dashoffset特性。下圖是倒計(jì)時(shí)運(yùn)行效果:

SVG實(shí)現(xiàn)多彩圓環(huán)倒計(jì)時(shí)效果的示例代碼

SVG倒計(jì)時(shí)案例

下面說說相關(guān)的實(shí)現(xiàn)代碼。css實(shí)現(xiàn)代碼如下:

svg {
    transform: rotate(-0.05deg);
}
circle {
    transition: stroke-dasharray .2s;
}
.time-count-x {
    line-height: 1.5;
    position: relative;
}
.time-second {
    position: absolute;
    top: 50%; left: 0; right: 0;
    margin-top: -.75em;
    text-align: center;
    font-size: 100px;
}

相關(guān)html代碼如下:

<div id="timeCountX" class="time-count-x">
    <svg width="440" height="440" viewBox="0 0 440 440" class="center">
        <defs>
            <linearGradient x1="1" y1="0" x2="0" y2="0" id="gradient1">
                <stop offset="0%" stop-color="#e52c5c"></stop>
                <stop offset="100%" stop-color="#ab5aea"></stop>
            </linearGradient>
           <linearGradient x1="1" y1="0" x2="0" y2="0" id="gradient2">
                <stop offset="0%" stop-color="#4352f3"></stop>
                <stop offset="100%" stop-color="#ab5aea"></stop>
            </linearGradient>
        </defs>
        <g transform="matrix(0,-1,1,0,0,440)">
            <circle cx="220" cy="220" r="170" stroke-width="50" stroke="#f0f1f5" fill="none" stroke-dasharray="1069 1069"></circle>
            <circle cx="220" cy="220" r="170" stroke-width="50" stroke="url('#gradient1')" fill="none" stroke-dasharray="1069 1069"></circle>
            <circle cx="220" cy="220" r="170" stroke-width="50" stroke="url('#gradient2')" fill="none" stroke-dasharray="534.5 1069"></circle>
        </g>
    </svg>
    <span id="timeSecond" class="time-second"></span>
</div>

最后是相關(guān)JavaScript代碼:

var eleCircles=document.querySelectorAll("#timeCountX circle");
var eleTimeSec=document.getElementById("timeSecond");
var perimeter=Math.PI*2*170;
var circleInit=function(){
    if(eleCircles[1]){
        eleCircles[1].setAttribute("stroke-dasharray","1069 1069")
    }
    if(eleCircles[2]){
        eleCircles[2].setAttribute("stroke-dasharray",perimeter/2+" 1069")
    }
    eleTimeSec.innerHTML=""
};
var timerTimeCount=null;
var fnTimeCount=function(b){
    if(timerTimeCount){
        return
    }
    var b=b||10;
    var a=function(){
        var c=b/10;
        if(eleCircles[1]){
            eleCircles[1].setAttribute("stroke-dasharray",perimeter*c+" 1069")
        }
        if(eleCircles[2]&&b<=5){
            eleCircles[2].setAttribute("stroke-dasharray",perimeter*c+" 1069")
        }
        if(eleTimeSec){
            eleTimeSec.innerHTML=b
        }
        b--;
        if(b<0){
            clearInterval(timerTimeCount);
            timerTimeCount=null;
            alert("時(shí)間到!");
            circleInit()
        }
    };
    a();
    timerTimeCount=setInterval(a,1000)
};
fnTimeCount();

整個(gè)案例的代碼非常少,有喜歡的朋友可以將代碼保存到html中,運(yùn)行一下,體驗(yàn)體驗(yàn)實(shí)際效果。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持。

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。
svg

相關(guān)文檔推薦

主站蜘蛛池模板: 黄免费观看视频 | 欧美精品久久一区 | 性福视频在线观看 | 黄色网址在线免费观看 | 一区二区三区亚洲精品国 | 免费同性女女aaa免费网站 | 亚洲不卡一 | 亚洲精品日韩一区二区电影 | 国产一区h | 亚洲国产精品99久久久久久久久 | 免费h视频| 成人在线视频一区 | www.久| 国产视频一视频二 | 亚洲成人播放器 | 亚洲国产在 | 天天玩天天操天天干 | 一区二区三区精品视频 | 中文字幕亚洲区 | 国产成人99久久亚洲综合精品 | 91免费福利在线 | www.一区二区三区 | 国产亚洲精品久久久久动 | 嫩草视频在线免费观看 | 二区在线视频 | 亚洲欧美日韩久久久 | 91视频一88av | 中文av在线播放 | 亚洲精品一二三区 | 午夜视频在线观看网址 | 日韩福利在线 | 综合国产第二页 | 中文字幕亚洲区 | 另类在线| 欧美激情亚洲激情 | 99精品久久 | 精品国产18久久久久久二百 | 天堂在线网 | 中文字幕亚洲一区 | 精品日韩 | 韩日一区二区三区 |