What is the fastest way to move a rectangular (pixel) region inside a HTML5 canvas element

后端 未结 2 791
孤街浪徒
孤街浪徒 2021-01-02 17:02

I want to implement vertical scrolling of the contents of a HTML5 canvas element. I don\'t want to render the whole content again. Instead I would like to move the whole con

2条回答
  •  醉梦人生
    2021-01-02 17:43

    Try this:

    ctx.drawImage(ctx.canvas, 0, 0, width, height-20, 0, 20, width, height-20);
    

    drawImage can take either an HTMLImageElement, an HTMLCanvasElement, or an HTMLVideoElement for the first argument.

提交回复
热议问题