質問

I'm new to Raphael and can understand most of the basics involved, but been stuck on this for a while now, I believe I have a simple syntax error in the if statement found in my click function

button.click(function() {
        //when the variable has been clicked
        light.animate({
            //The variable light will animate
            if(light.attr("fill") == "#ffffff"){
                //if the light has a fill of white
            fill: '#FFFF00'
                //then it will change to yellow
            }
            else(){
                //else if the light has any other colour
            fill: '#ffffff'
                //then it will fill the light with white
            }
            //fill: '#FFFF00'
            }, 5000);
            //it will take five seconds for the new colour to be fully lit up
    });
役に立ちましたか?

解決

I'm not into Raphael that much buut you have the JS syntax wrong. Maybe this will help:

if (light.attr("fill") == "#ffffff" ){
    light.animate({
        fill: '#FFFF00'
    }, 5000);
} else {
    light.animate({
        fill: '#ffffff'
    }, 5000);
}

Hope this helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top