← Previous Next →

Scrawl-canvas v8 - DOM test 011

Canvas controller 'fit' attribute; Cell positioning (mouse)

Canvas fit
Stack dimensions
Width:
Height:
Cell set rel dims using base

To note: Javascript is not running in this browser environment. Our apologies, but this demo has not yet been updated to support progressive enhancement.

Test purpose

We set up a Scrawl-canvas Stack artefact (a <div> element) in HTML, whose dimensions can be controlled by the user. The element is given a red background color, and initial dimensions of 400px by 400px. Within the Stack, we include a <canvas> element and mark it as responsive, so its dimensions will always match its parent Stack element's dimensions. This canvas has a yellow background color, set via CSS.

We set the canvas element's base canvas (which is not part of the DOM) to have fixed dimensions (800px by 600px) and tell the canvas to fit its base canvas into itself using the 'fill' algorithm. The user can change the fit parameter to other algorithms ('cover', 'contain', 'none'). The base canvas is given a background color of light green via the <canvas> element's `data-base-background-color` attribute.

Finally we add a non-base Cell to the canvas. This has relative dimensions of 50% by 50%, scaled by a factor of 1.1 and rotated 10deg. The non-base Cell will initially calculate its dimensions relative to the display canvas's dimensions; the user can change this by updating the Cell's `setRelativeDimensionsToBase` attribute to `true`. The Cell has a background color of dark blue.

See Demo Canvas-036 for additional Cell functionality tests.

Touch test: should work as expected

Annotated code