javascript中的switch语句出现问题

时间:2014-02-18 14:45:09

标签: javascript switch-statement

我要创建一个显示音乐视频的网络应用程序。我创建了一些带有视频,播放按钮,画布的html,其中我展示了一些音频条和一些名为“intro”,“verse”和“guitar solo”的标题。

当歌曲从一个部分转到另一个部分时,我想在标题之间切换。但是我的switch语句似乎不起作用。我在第49行收到错误。

我的Javascript看起来像这样。

我很感激我对错误的看法:)

var video = 5;
var analyser;var canvas;
var time;

$(function() {
    video = $("video")[0];
    $("body").on("click", "#playbutton", startStopVideo);

    createAudioAnalyser();
});



function createAudioAnalyser() {
    context = new webkitAudioContext();
    analyser = context.createAnalyser();
    canvas = $('#soundwave')[0]; 
    ctx = canvas.getContext('2d');

    source = context.createMediaElementSource(video); 
    source.connect(analyser);
    analyser.connect(context.destination);
}

function soundAnimation() {
    window.requestAnimationFrame(soundAnimation); 
    analyser.fftSize = 128;
    fbc_array = new Uint8Array(analyser.frequencyBinCount);
    analyser.getByteFrequencyData(fbc_array);
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = 'rgba(0,90,255,0.3)'; 
    bars = 120;
    for (var i = 0; i < bars; i++) {
        bar_x = i * 3;
        bar_width = 2;
        bar_height = -(fbc_array[i]);

        ctx.fillRect(bar_x, canvas.height, bar_width, bar_height);
    }
}

//this thing gives an error
setInterval(function() {
    myVid = document.getElementById("video");
    time = parseInt(myVid.currentTime,10);
    switch(time) {
        case 2
            $("#intro").switchClass("activebox", "inactivebox");  // Here's the error... what is it?
        break;
    }
},1000);
//---------

function startStopVideo() {

    if(video.paused) {
        video.play();
        soundAnimation();
    } else {
        video.pause();
    }
}

1 个答案:

答案 0 :(得分:4)

错字:

case 2

应该是:

case 2:
//    ^ You missed that.