我试图通过范围输入更改运行时的值,但我无法让它工作。我没有收到任何错误。当我更改 onSlide 中的频率时,声音仍然以 800 播放。它应该会改变。
import $ from 'jquery';
import rangeslider from 'rangeslider.js';
import T from 'timbre';
window.$ = $;
$(document).ready(() => {
var f = 800;
T("sin", {freq:f, mul:0.5}).play(); /*plays a continous sound*/
$('input[type="range"]').rangeslider({
polyfill : false,
onSlide: function() {
var ff = 440; /*changing frequancy, but the tone is still the same.*/
f = ff;
}
});
});
最佳答案
如Getting Started所示,您需要将实例存储在变量中,以便可以调用 set
method稍后。
$(document).ready(() => {
const tone = T("sin", {freq:f, mul:0.5}).play(); /*plays a continous sound*/
$('input[type="range"]').rangeslider({
polyfill : false,
onSlide: function() {
tone.set( {freq: 440 }); /* changing frequency of the tone */
}
});
});
关于javascript - 在运行时更改值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47939551/