jQuery+CSS实现环形进度条
2015-12-11 11:58
507 查看
HTML代码:
<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>
CSS代码:
.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(0deg);
}
.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;
}
jQuery代码:
$(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)");
};
});
});
<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>
CSS代码:
.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(0deg);
}
.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;
}
jQuery代码:
$(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)");
};
});
});
相关文章推荐
- jquery彩色投票进度条简单实例演示
- jquery模拟进度条实现方法
- PHP设置进度条的方法
- jquery实现模拟百分比进度条渐变效果代码
- js ajax加载时的进度条代码
- javascript实现简单的进度条
- js插件YprogressBar实现漂亮的进度条效果
- ajax 异步上传带进度条视频并提取缩略图
- 基于jquery步骤进度条源码分享
- jquery插件NProgress.js制作网页加载进度条
- jquery实现加载进度条提示效果
- jQuery实现页面顶部显示的进度条效果完整实例
- jQuery实现文件上传进度条特效
- jQuery实现简单的文件上传进度条效果
- 分享8款优秀的 jQuery 加载动画和进度条插件
- 自定义刻度jQuery进度条及插件
- 利用Asp.Net回调机制实现进度条
- FCKeditor 图片上传进度条不动的解决方法
- javascript 实现页面加载进度条代码
- Extjs实现进度条的两种便捷方式