1 回答
TA贡献1906条经验 获得超10个赞
我只是addEventListener
在事件中使用该方法input
//default ramp size parameters
let rampHeight = 200;
let rampLength = 150;
function setup() {
//createCanvas(800, 500);
var slider = document.getElementById('height');
var input = document.getElementById('heightInput');
slider.addEventListener('input', function(){
input.value = changeHeight(this.value);
});
input.addEventListener('input', function(){
slider.value = this.value;
});
}
function draw() {
background(220);
fill(150);
triangle(700, rampHeight, 700, 400, rampLength, 400);
}
function changeHeight(height) {
rampHeight = 500 - height * 10;
if (height >= 20 && height <= 40) {
return rampHeight;
} else if (height > 40) {
return rampHeight = 100;
} else if (height < 20) {
return rampHeight = 300;
}
}
setup();
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/addons/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="height" type="range" min="20" max="40" value="30">
<div class="input-amount">
<input id="heightInput" name="price" value="30">
</div>
</body>
</html>
添加回答
举报