javascript - 在运行时更改值

标签 javascript ecmascript-6 timbre

我试图通过范围输入更改运行时的值,但我无法让它工作。我没有收到任何错误。当我更改 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/

相关文章:

javascript - 使用 call 或 apply 调用闭包中的函数?

javascript - 在 Angular2 中导入接口(interface)

javascript - 使用 javascript .bind() 方法跳过参数

javascript - 没有偏应用的 curry 函数?

javascript - ES6 模块未按预期在 React 中导入

javascript - JSHint - ^ 'concise methods' 在 ES6 中可用

clojure - 音色宏 'p' 无法解析,但其他音色宏可以解析

Clojure:音色和 clojure.test 命名空间

javascript - 关于在 JavaScript 中创建对象的问题