0
我想建立一個餅圖,它根據範圍輸入的值動態改變。如何用JavaScript改變餅圖片的背景顏色?
這是我迄今所做的:https://codepen.io/anon/pen/wqQLPy
const $slider = document.querySelector('input[type=range]');
const $line2 = document.querySelector('.line2');
$slider.addEventListener('input', handleChange);
function handleChange() {
//$currrentValue.textContent = this.value;
const degrees = 90 + ((this.value/100) * 360);
$line2.style.transform = `rotate(${degrees}deg)`;
}
.pie {
width: 250px;
height: 250px;
margin: 0 auto;
border-radius: 50%;
border: 3px solid white;
position: relative;
background: #ffc600;
overflow: hidden;
}
.line {
width: 50%;
height: 2px;
background: #555;
position: absolute;
top: 50%;
transform-origin: 100%;
transform: rotate(90deg);
transition: all .2s linear;
}
.line2 {
transform: rotate(180deg);
/* When input value is 25 (default) */
}
<input type="range" min="0" max="100" value="25">
<div class="pie">
<div class="line line1"></div>
<div class="line line2"></div>
</div>
我的問題是 - 如何設置不同的背景顏色與切片(兩條線之間的區域)?
例子: