【发布时间】:2018-02-21 13:31:33
【问题描述】:
如何创建一个颜色根据百分比变化的进度条 我想根据给定的值(js & css)改变条形的颜色以平滑变化
例如:0% = 绿色,100% = 红色,75% = 橙色(红色和绿色之间的渐变) css中的这段代码:
<style>
#myBar {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: #ff0000;
text-align: center;
line-height: 30px;
color: white;
border-radius: 1em;
animation: color 2s linear 0s alternate;
}
@keyframes color{
0% {background-color: #0f0;}
50% {background-color: #ff0;}
100% {background-color: #f00;}
}
</style>
文件 index.php 中的这段代码:
<script>
function move() {
var elem = document.getElementById("myBar");
var newElem = document.getElementById("percent");
var height = 1;
score = <?php echo($percentation);?>;
var id = setInterval(frame, 25);
function frame() {
if (height >= score) {
clearInterval(id);
} else {
height++;
elem.style.height = height + '%';
newElem.innerHTML = height + '%';
}
}
}
</script>
myBar 是加载栏本身的 div percent 是 div 输出值
【问题讨论】:
标签: javascript php html css