-
type CoreOptions = {
container: string;
};
class Render {
private _canvas: HTMLCanvasElement;
private _container!: {
element: HTMLElement;
width: number;
height: number;
};
private _ResizeObserver: ResizeObserver;
public _FC: Canvas;
constructor(private options: CoreOptions) {
this.init();
}
private init = () => {
this._canvas = document.createElement('canvas');
this._canvas.style.position = 'absolute';
this._canvas.style.top = '0';
this._canvas.style.left = '0';
this._container = getContainer(this.options.container);
this._container.element.style.position = 'relative';
this._container.element.appendChild(this._canvas);
this._FC = new Canvas(this._canvas, {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
interactive: true,
isDrawingMode: false,
preserveObjectStacking: true,
enableRetinaScaling: true,
renderOnAddRemove: true,
});
this.setCanvasSize();
this.initResizeObserver();
};
private setCanvasSize = () => {
this._container = getContainer(this.options.container);
this._FC.setDimensions({
width: this._container.width,
height: this._container.height,
});
};
private initResizeObserver = () => {
this._ResizeObserver = new ResizeObserver(() => {
this.setCanvasSize();
});
this._ResizeObserver.observe(this._container.element);
};
} This is my code, I want the canvas to resize when the container size changes. When I resize the browser window the canvas is flickering |
Beta Was this translation helpful? Give feedback.
Answered by
asturur
Jan 11, 2025
Replies: 2 comments 1 reply
-
2025-01-10.16.22.07.mov |
Beta Was this translation helpful? Give feedback.
0 replies
-
I added the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setDimension is going to render at the next animation frame, if you call renderAll right away you could avoid flickering. There should be no side effects.