0

我试图通过范围输入在运行时更改一个值,但我没有让它工作。我没有错误。当我在 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;
            }
        });

    });
4

1 回答 1

1

入门中所示,您需要将实例存储在一个变量中,以便稍后调用该set 方法。

$(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 */
        }
    });
});
于 2017-12-22T10:13:53.980 回答