[英]How do i set a function parameter with JavaScript?
如何使用 JavaScript 設置函數參數? 我需要為變量設置一個數值,但我似乎無法弄清楚。 一些幫助將不勝感激!
// create web audio api context
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create Oscillator node
var oscillator = audioCtx.createOscillator();
oscillator.type = 'square';
oscillator.frequency.setValueAtTime(255, audioCtx.currentTime); // I want to set 255 to the variable x
oscillator.connect(audioCtx.destination);
oscillator.start();
var x = document.getElementById("HTMLslider").value;
我試過這樣做:
set oscillator.frequency = var "x"
希望有人能幫忙😁
我猜您想根據滑塊值更改頻率:
var slider = document.getElementById("HTMLslider"); // create web audio api context var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); // create Oscillator node var oscillator = audioCtx.createOscillator(); oscillator.type = 'square'; oscillator.frequency.setValueAtTime(Number(slider.value), audioCtx.currentTime); // I want to set 255 to the variable x oscillator.connect(audioCtx.destination); oscillator.start(); // Listen for slider changes and apply value to frequency. slider.addEventListener('change', e => oscillator.frequency.setValueAtTime(Number(e.target.value), audioCtx.currentTime));
<input type="range" min="1" max="1000" value="225" id="HTMLslider" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.