css 倒計時 svg

來源:互聯網
上載者:User

標籤:des   style   class   blog   http   tar   

<!DOCTYPE html><html> <head>    <meta charset="utf-8" />  <meta name="author" content="" />  <meta name="keywords" content="" />  <meta name="description" content="" />  <title> new document </title>  <style>     div{position:absolute;width:200px;height:200px;left:0;top:0;right:0;bottom:0;margin:auto;border-radius:50%;background-color:#CCC;}     div:before,     div:after{position:absolute;content:"";width:50%;height:100%;top:0;left:0;background-color:#CCC;border-radius:100% 0 0 100%/50% 0 0 50%;z-index:1;transform-origin:100% 50%;-webkit-transform-origin:100% 50%;-moz-transform-origin:100% 50%;-o-transform-origin:100% 50%;}     div.half,     div:before{background-color:gold;}     div{animation:run 10s steps(1,end);-webkit-animation:run 10s steps(1,end);-moz-animation:run 10s steps(1,end);-o-animation:run 10s steps(1,end);}     div:before{animation:run1 10s linear;-webkit-animation:run1 10s linear;-moz-animation:run1 10s linear;-o-animation:run1 10s linear;}     div span{position:absolute;width:100%;height:22px;left:0;top:90px;font-size:20px;font-weight:bold;line-height:22px;text-align:center;z-index:5;}     @keyframes run{        50%,        100%{background-color:gold;}     }     @keyframes run1{        100%{z-index:3;transform:rotate(360deg);}     }     @-webkit-keyframes run{        50%,        100%{background-color:gold;}     }     @-webkit-keyframes run1{        100%{z-index:2;-webkit-transform:rotate(360deg);}     }

  svg倒計時

<!DOCTYPE html><html><meta charset="utf-8"><title>svg做的倒計時</title><body><div id="svgBox"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500" height="500"> <path id="test1" style="fill:#fe0; stroke:#fff; stroke-width:0;"/><text x="93" y="100" fill="green" id="text">1</text></svg><script>window.onload=function(){num = 360 ;var time = setInterval(j,10);function j(){ num = num - 1; i = parseInt(num/360*100); var text_ = document.getElementById("text");  text_.textContent = i;//svg節點是xml,所以只能用textContent代替innerHTML來擷取文本節點 var startAngle=90; var cx = 100;//svg與y軸的距離 var cy = 100;//svg與x軸的距離 var r = 100;//圓的半徑 var deg1 = num + startAngle;  var x0 = cx+r*Math.cos(startAngle*Math.PI/180); var y0 = cy-r*Math.sin(startAngle*Math.PI/180); var x1 = cx+r*Math.cos(deg1*Math.PI/180);  var y1 = cy-r*Math.sin(deg1*Math.PI/180);  var a = num<180 ? 0 : 1; var test = document.getElementById("test1"); //畫筆落在(cx,cy),畫線至(x0,y0),畫圓弧(從當前點到x1,y1畫橢圓,r,r為長短半軸,偏轉0度,大圓弧或小圓弧,逆時針或順時針,閉合路徑) test.setAttribute("d","M "+cx+","+cy+" L "+x0+","+y0+" A "+r+","+r+" 0 "+a+",0 "+x1+","+y1+" Z"); if(num<1){ text_.setAttribute("fill","red"); window.clearInterval(time); console.log("時間到了昂~~~"); }};};</script></div></body></html>

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.