Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 画布动画套件实验。。。如何清理画布?_Javascript_Animation_Html_Canvas - Fatal编程技术网

Javascript 画布动画套件实验。。。如何清理画布?

Javascript 画布动画套件实验。。。如何清理画布?,javascript,animation,html,canvas,Javascript,Animation,Html,Canvas,我可以制作一个obj,使用画布绘制如下: MyObj.myDiv = new Canvas($("effectDiv"), Setting.width, Setting.height); 然后,我使用它在画布上绘制一个矩形: var c = new Rectangle(80, 80, { fill: [220, 40, 90] } ); var move = new Timeline; move.add

我可以制作一个obj,使用画布绘制如下:

MyObj.myDiv = new Canvas($("effectDiv"), Setting.width,  Setting.height);
然后,我使用它在画布上绘制一个矩形:

    var c =  new Rectangle(80, 80,
        {
            fill: [220, 40, 90]
        }
    );
    var move = new Timeline;
    move.addKeyframe(0,
        {
            x: 0,
            y: 0
        }
    );
    c.addTimeline(move);
    MyObj.myDiv.append(c);
canvas.clear = true; // makes the canvas clear itself on every frame
canvas.fill = somecolor; // fills the canvas with some color on every frame
// with canvas.clear = false and low-opacity fill, fancy motion blur effect

Removing the rectangle from the canvas:
rectangle.removeSelf();
or
canvas.removeChild(rectangle);
但是在我画了矩形之后,我想清除画布,但我不知道是哪种方法,怎么做

还有一件事: 这是蛋糕的网站:

您可以尝试以下方法:

MyObj.myDiv.clearRect(0, 0, canvas.width, canvas.height);
有效地将整个画布着色为背景色。

清除画布:

    var c =  new Rectangle(80, 80,
        {
            fill: [220, 40, 90]
        }
    );
    var move = new Timeline;
    move.addKeyframe(0,
        {
            x: 0,
            y: 0
        }
    );
    c.addTimeline(move);
    MyObj.myDiv.append(c);
canvas.clear = true; // makes the canvas clear itself on every frame
canvas.fill = somecolor; // fills the canvas with some color on every frame
// with canvas.clear = false and low-opacity fill, fancy motion blur effect

Removing the rectangle from the canvas:
rectangle.removeSelf();
or
canvas.removeChild(rectangle);
最简单的方法是:

MyObj.myDiv.width = MyObj.myDiv.width;

我发现调整画布的大小就像变魔术一样,即使你没有真正改变大小:

canvas.width = canvas.width

请注意,不管有什么说法,这对Safari并不完全有效。请注意,不管有什么说法,这对Safari也不完全有效。