日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

环形进度条

發(fā)布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 环形进度条 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

jQuery + CSS3

實現(xiàn)原理

原理非常的簡單,在這個方案中,最主要使用了CSS3的transform中的rotate和CSS3的clip兩個屬性。用他們來實現(xiàn)半圓和旋轉(zhuǎn)效果。

半環(huán)的實現(xiàn)

先來看其結(jié)構(gòu)。

html

<div class="pie_right"><div class="right"></div><div class="mask"><span>0</span>%</div> </div>

  css

.pie_right {width:200px; height:200px;position: absolute;top: 0;left: 0;background:#0cc; } .right {width:200px; height:200px;background:#00aacc;border-radius: 50%;position: absolute; top: 0;left: 0; } .pie_right, .right {clip:rect(0,auto,auto,100px); } .mask {width: 150px;height: 150px;border-radius: 50%;left: 25px;top: 25px; background: #FFF;position: absolute;text-align: center;line-height: 150px;font-size: 20px;background: #0cc;/* mask 是不需要剪切的,此處只是為了讓大家看到效果*/clip:rect(0,auto,auto,75px); }

  實現(xiàn)半圓還是挺簡單的,利用border-radius做出圓角,然后利用clip做出剪切效果,(clip使用方法,詳見站內(nèi)介紹),mask的部分是為了遮擋外面的容器,致使在視覺上產(chǎn)生圓環(huán)的效果:

旋轉(zhuǎn)的話,那更容易實現(xiàn)了,就是在CSS的right中加入.right { transform: rotate(30deg); }

這樣就可以看到一個半弧旋轉(zhuǎn)的效果了。

整環(huán)的實現(xiàn)

同樣道理,拼接左半邊圓環(huán)

<div class="circle"><div class="pie_left"><div class="left"></div></div><div class="pie_right"><div class="right"></div></div><div class="mask"><span>0</span>%</div> </div>

  

.circle {width: 200px;height: 200px; position: absolute;border-radius: 50%;background: #0cc; } .pie_left, .pie_right {width: 200px; height: 200px;position: absolute;top: 0;left: 0; } .left, .right {display: block;width:200px; height:200px;background:#00aacc;border-radius: 50%;position: absolute;top: 0;left: 0;transform: rotate(30deg); } .pie_right, .right {clip:rect(0,auto,auto,100px); } .pie_left, .left {clip:rect(0,100px,auto,0); } .mask {width: 150px;height: 150px;border-radius: 50%;left: 25px;top: 25px;background: #FFF;position: absolute;text-align: center;line-height: 150px;font-size: 16px; }

圓環(huán)最終效果

Ok了,基本上我們的圓環(huán)已經(jīng)實現(xiàn)完成了,下面是加入JS效果。

首先,我們需要考慮的是,圓環(huán)的轉(zhuǎn)動幅度大小,是由圓環(huán)里面數(shù)字的百分比決定的,從0%-100%,那么圓弧被分成了每份3.6°;而在180°,也就是50%進(jìn)度之前,左側(cè)的半弧是不動的,當(dāng)超過50%,左邊的半弧才會有轉(zhuǎn)動顯示。

$(function() {$('.circle').each(function(index, el) {var num = $(this).find('span').text() * 3.6;if (num<=180) {$(this).find('.right').css('transform', "rotate(" + num + "deg)");} else {$(this).find('.right').css('transform', "rotate(180deg)");$(this).find('.left').css('transform', "rotate(" + (num - 180) + "deg)");};});});

  

?

轉(zhuǎn)載于:https://www.cnblogs.com/zshh/p/5577457.html

總結(jié)

以上是生活随笔為你收集整理的环形进度条的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。