addCanvas - adds a new <canvas> element to Scrawl-canvas stack immediately before this element, and sets up the canvas to mimic the element (meaning it will mimic changes to the element’s dimensions, positioning, scale and 3D rotational values)
- The function can accept a Javascript object argument containing key:value pairs which will be used to set up the new canvas’s attributes after it has been created.
- To make the canvas look as if it is in front of the element, set the element’s opacity CSS attribute to 0
- This function is used when adding a Scrawl-canvas component to a stacked element.
P.addCanvas = function (items = {}) {
if (!this.canvas) {
let canvas = document.createElement('canvas'),
el = this.domElement;
let rect = el.getBoundingClientRect(),
style = window.getComputedStyle(el);
el.parentNode.insertBefore(canvas, this.domElement);
let art = makeCanvas({
name: `${this.name}-canvas`,
domElement: canvas,
position: 'absolute',
width: rect.width,
height: rect.height,
mimic: this.name,
lockTo: 'mimic',
useMimicDimensions: true,
useMimicScale: true,
useMimicStart: true,
useMimicHandle: true,
useMimicOffset: true,
useMimicRotation: true,
addOwnDimensionsToMimic: false,
addOwnScaleToMimic: false,
addOwnStartToMimic: false,
addOwnHandleToMimic: false,
addOwnOffsetToMimic: false,
addOwnRotationToMimic: false,
});
art.set(items);
this.canvas = art;
return art;
}
};