如何使我的技能图表使用一个分数字母,而不是百分比
How can I make my skills graph use a grade letter, rather than a percentage?
我到处寻找这个特定的需求,但找不到任何好的来源。我有一张"技能"图,可以显示我完成任务的能力。我的问题是,我不希望它显示百分比,而是字母等级(a+,a,B,C)
这是链接
这是代码
<script type="text/javascript">
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
function grow() {
var element = '.bar';
var i = 1;
$(element).each(function(index, value) {
var percent = $(this).attr('data-percent');
var timing = percent / 100;
setTimeout(function() {
$(value).css('max-width', +percent + '%').css('transition', timing + 's ease all');
$(value).append('<div class="num">' + percent + '%</div>');
}, i * 50);
i++;
});
}
$(window).load(function() {
requestAnimationFrame(grow);
});
</script>
.bar {
background: white;
border-top: 1px solid #b4996d;
width: 100%;
max-width: 0;
height: 25px;
margin: 0 0 10px 0;
border-top-style: dotted;
}
.num {
line-height: 22px;
color: #b4996d;
font-size: 12px;
text-align: right;
font-family: 'open_sansbold';
}
.label-graph {
line-height: 22px;
position: absolute;
color: #333;
font-size: 12px;
font-family: 'open_sansbold';
}
.holder {
margin: 0 auto;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="holder">
<div class="bar" data-percent="95">
<span class="label-graph">Web Design</span>
</div>
<div class="bar" data-percent="95">
<span class="label-graph">Graphic Design</span>
</div>
<div class="bar" data-percent="95">
<span class="label-graph">Photoshop</span>
</div>
<div class="bar" data-percent="80">
<span class="label-graph">HTML5</span>
</div>
<div class="bar" data-percent="90">
<span class="label-graph">Illustration</span>
</div>
<div class="bar" data-percent="85">
<span class="label-graph">Print</span>
</div>
</div>
下面是一个简单的例子,说明@lux在注释中的建议。你在data-percent
属性上添加条件,它就在:)上
点击此处查看
$(function(){
$('.bar').each(function(i,v){
data = $(this).data('percent');
// just an example, you can set whatever you wants as value and conditions
if(data > 80){
$(this).addClass('grade-Aplus');
}
else if(data <= 80 && data > 60){
$(this).addClass('grade-A');
}else{
$(this).addClass('grade-B');
}
});
});
CSS
.bar:before {content:""; width: 0; height: 30px; background: blue; position: absolute; left: 0; top: 0; transition: all 0.5s; }
.bar { position: relative; margin: 15px 0; padding: 7px 0 0 110px}
.bar.grade-Aplus:before { width: 100px; content: "A+"; color: #fff;}
.bar.grade-A:before { width: 80px; content: "A"; color: #fff}
.bar.grade-B:before { width: 30px; content: "B"; color: #fff}
/* and so on ... :) */
相关文章:
- 递增一个数字而不去掉前导零
- 如何为jQuery屏蔽输入插件创建一个允许字母数字、空格和重音字符的掩码
- 我想在AngularJS应用程序中创建一个输入数字框,用户不应该在该框上键入十进制数字.(一个整数输入框)
- 制作一个regex来验证只有一个数字的字符串
- 如何限制一个字段只接受4个数字字符作为输入,并获得'It’这是潜水警报
- 为什么这个正则表达式不't匹配最后一个字母数字字符
- 一个jquery验证器方法,它不接受纯数字或纯特殊字符,但接受上面是否有字母
- 如何拆分一个整数和产生的所有数字来创建一个新数字
- 如何使用至少一个数字、一个大写字母和6-20个字符验证密码
- 当与另一个实例进行比较时,我的类实例如何隐式返回数字
- 简单的Javascript方式,在输入字段的每5位数字后添加一个空格
- 有没有办法在里面看到一个数字'的64位浮点IEEE754表示
- PHP函数识别3个数字中最低的一个并更改其类
- 我如何解析二's是一个数字的补码字符串
- 为什么我需要在这里输入var,为什么它会给我一个数字作为答案?(Javascript)
- 在我的网站上创建一个在1-10之间不断变化的数字时遇到了问题.Javascript
- 如何获取一个以零开头的数字的位数
- 如何创建一个确定2个数字之间值的函数
- 当我添加一个新数字时,如何获得一些数字的即时平均值
- 为什么 JavaScript 如果一个数字有一个前导零,就将其视为八进制