我想用範圍滑塊控制變量長度,以便滑塊可以增加或減少線的長度。帶滑塊的控制變量
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
\t
var slider = document.getElementById("slider");
var length = 450
context.beginPath();
context.moveTo(100, 100);
context.lineTo(length, 100);
context.stroke();
\t
\t
slider.addEventListener("change", function() {
length = slider.value;
})
setInterval(function() {
length = slider.value;
}, 100)
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<input id="slider" type="range" min="1" max="578" step="1" value="50" >
<canvas id="myCanvas" width="578" height="200"></canvas>
</body>
</html>
請什麼或不工作的詳細說明。 –