page-flip
Version:
Powerful, simple and flexible JS Library for creating realistic and beautiful page turning effect
44 lines (34 loc) • 1.1 kB
text/typescript
import {UI} from "./UI";
import {PageFlip} from "../PageFlip";
import {FlipSetting} from "../Settings";
/**
* UI for canvas mode
*/
export class CanvasUI extends UI {
private readonly canvas: HTMLCanvasElement;
constructor(inBlock: HTMLElement, app: PageFlip, setting: FlipSetting) {
super(inBlock, app, setting);
this.wrapper.innerHTML = '<canvas class="stf__canvas"></canvas>';
this.canvas = inBlock.querySelectorAll('canvas')[0];
this.distElement = this.canvas;
this.resizeCanvas();
this.setHandlers();
}
private resizeCanvas(): void {
const cs = getComputedStyle(this.canvas);
const width = parseInt(cs.getPropertyValue('width'), 10);
const height = parseInt(cs.getPropertyValue('height'), 10);
this.canvas.width = width;
this.canvas.height = height;
}
/**
* Get canvas element
*/
public getCanvas(): HTMLCanvasElement {
return this.canvas;
}
public update(): void {
this.resizeCanvas();
this.app.getRender().update();
}
}