1
我發現這個代碼在stackoverflow緩慢地淡出音軌。它運作良好。它的結構方式使我很難在沒有複製和粘貼的情況下重複使用,因爲函數本身會自行調用。以下是代碼:我將如何將這段代碼放入一個可重用的函數中?
function fadeVolume(volume, callback) {
//change the volume by factor each time
//will check if setTimeout is used to loop as well as wait, as it seems so here
var factor = 0.02,
speed = 50;
if (volume > factor) {
setTimeout(function() {
fadeVolume((gameController.myAudio.preGameTrack.volume -= factor), callback);
}, speed);
} else {
(typeof (callback) !== 'function') || callback();
}
};
fadeVolume(gameController.myAudio.preGameTrack.volume, function() {
preGameContent.ready = true;
//stop the music altogether
gameController.myAudio.preGameTrack.pause();
gameController.myAudio.preGameTrack.currentTime = 0;
})
你的問題是什麼?您是否無法將其保存到文件中,並使用'