Loading the Scrawl-canvas library using a script tag in the HTML code
Scrawl-canvas is added to the page through a <script> tag at the bottom of the html code. The tag takes the following attributes:
<script type="module">[Scrawl-canvas code goes here]</script>
... or:
<script src="dom-001.js" type="module"></script>
- src= - path to the user code which imports the scrawl.js file
- type="module" - user code needs to be modular (ES6 style) - it has an import instruction at the top of the file
By importing the scrawl.js file, the browser will also import all the related files required by Scrawl-canvas. The import code goes at the top of the user code (in this demo, the dom-001.js file):
import scrawl from '../../relative/path/to/scrawl.js';
... or if the library has been included via NPM or Yarn:
import scrawl from 'scrawl-canvas';
... or if using the remote CDN version:
import scrawl from 'https://unpkg.com/scrawl-canvas@8.2.3';
The import doesn't need to be called 'scrawl' - it can be whatever the user prefers.
element in a nested stack
Test purpose
- Import the scrawl.js file
- Import all other required Scrawl-canvas files
- Discover and prepare stack elements in the DOM
- Discover and prepare child elements in each stack element
- Discover and prepare the <canvas> element
- Track the mouse over the root stack element
Annotated code