Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Forked from jdanyow/app.html
Created March 11, 2016 15:37
Show Gist options
  • Save AshleyGrant/bd093ad54032055da1da to your computer and use it in GitHub Desktop.
Save AshleyGrant/bd093ad54032055da1da to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<div style="height: 125px; min-width: 150px; width: 100%;" ref="canvasContainer">
<canvas ref="canvas" width.one-way="canvasContainer.offsetWidth"></canvas>
</div>
</template>
import {PLATFORM} from 'aurelia-pal';
export class App {
resizeTimer = null;
resizeEventHandler = () => this.resized();
attached() {
this.resized();
PLATFORM.global.addEventListener("resize", this.resizeEventHandler);
}
detached() {
PLATFORM.global.removeEventListener("resize", this.resizeEventHandler);
}
resized() {
clearTimeout(this.resizeTimer);
this.resizeTimer = setTimeout(() => {
let ctx = this.canvas.getContext("2d");
ctx.fillStyle = "green";
ctx.font = "30px Arial";
ctx.fillText(`Width: ${this.canvas.width}`,10,50);
}, 150);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment