第一个函数触发第二个

时间:2016-07-13 11:36:48

标签: javascript

我在javascript上很糟糕,如何在第一次完成音量淡入淡出时调用/触发功能2(连续性)得到功能1(淡入淡出)。我在JQuery中找到了答案,我如何在纯JS中做到这一点。

功能1:

 function fade(){
        "use strict";
        var timepiece,
        soundwaves = document.getElementsByTagName("video")[0];
        if (soundwaves.volume > 0) {
        soundwaves.volume -= 0.005;
        timepiece = setTimeout(fade, 80);
            }
        }

功能2:

        <!-- Continuity: (Javascript) -->

        function continuity(){
        var elements = document.querySelectorAll("main")[0];
        elements.style.transition = "opacity 3s linear 0s";
        elements.style.opacity = 1.0;

        var audiofade,
        audio = document.getElementById("ambience");
        if (audio.volume < 1.0) {
        audio.volume += 0.005;
        audiofade = setTimeout(sync, 80);
        }
            }

1 个答案:

答案 0 :(得分:1)

只需在else

中调用第二个
function fade()
{
    "use strict";
    var timepiece,
    soundwaves = document.getElementsByTagName("video")[0];
    if (soundwaves.volume > 0) 
    {
        soundwaves.volume -= 0.005;
        timepiece = setTimeout(fade, 80);
    }
    else
    {
       continuity();
    }
}