CSS3實現炫酷進度條

來源:互聯網
上載者:User

看了一個進度條很漂亮,所以自己試試看


html

<div class="load-container"><span class="run"></span><div class="meter">0</div></div>


css樣式:

* {margin: 0;padding: 0;font-family: 'microsoft yahei';}html,body {width: 100%;height: 100%;background-color: #222;}.load-container {width: 600px;height: 6px;margin: 0 auto;margin-top: 200px;background-image: -webkit-linear-gradient(left,#5bd8ff, #ff0000);border-radius: 5px;position: relative;}.run {position: absolute;    width: 0px;    height: 6px;    right: 0px;    background: #000;    border-radius: 5px;    animation: runnAnimation 10s linear;}@keyframes runnAnimation {0% {width: 600px;}100% {width: 0px;}}.run:after {content: "";display: block;width: 16px;height: 16px;border-radius: 50%;background-color: #f00;margin-left: -4px;margin-top: -4px;animation: destination 10s linear;}@keyframes destination {0% {background-color: #5bd8ff;}100% {background-color: red;}}.meter {float: right;margin-top: 10px;    font-size: 40px;    color: red;    animation: fontColor 10s linear;}@keyframes fontColor {0% {color: #5bd8ff;}100% {color: red;}}.meter:after {content: "%"}

js代碼如下:

window.onload = function() {var meter = document.querySelector('.meter');run(meter,100);function run(el,time) {time = time ? time : 100;el = el ? el : document;var i = 0;var timer = setInterval(function() {if(i<100) {i++;el.innerHTML = i;} else {clearInterval(timer);}},time)}}


效果圖:



如果想要調整進度時間,需要修改css樣式中animation的時間和js中的時間



PS:css未做首碼處理,所有測試都在最新Google瀏覽器下進行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.