在运行时更改值

时间:2017-12-22 10:04:57

标签: 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;
            }
        });

    });

1 个答案:

答案 0 :(得分:1)

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 */
        }
    });
});