1

次の関数を使用してキャンバスを動的に作成しました。

var animating=false;
function create_canvas(Container,Id,Width,Height)
{
 ...//set width,height
 //added a click event listener
 document.getElementById(Id).addEventListener("click", function () 
        {
            if(animating==true)
            {
                alert("Running the animation"); //can't reach this part 
                return;
            }
            else
            {
                animating=true;
                run_canvas();
                animating=false;
            }
        });
 ...//append to Container
}
function run_canvas()
{
 ...//some code here 
}

キャンバスをクリックするたびに、何があってもアニメーションが開始されます。つまり、グローバル変数のアニメーションでは値が変更されないということです。したがって、私の質問: 何が間違っているのか、この種の状況にどのように対処すればよいでしょうか。

4

1 に答える 1