Konva
Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d contex...
README
Konva
Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.
You can draw things onto the stage, add event listeners to them, move them, scale them, and rotate them independently from other shapes to support high performance animations, even if your application uses thousands of shapes. Served hot with a side of awesomeness.
This repository began as a GitHub fork of ericdrowell/KineticJS.
Quick Look
- ``` html
- <script src="https://unpkg.com/konva@8/konva.min.js"></script>
- <div id="container"></div>
- <script>
- var stage = new Konva.Stage({
- container: 'container',
- width: window.innerWidth,
- height: window.innerHeight,
- });
- // add canvas element
- var layer = new Konva.Layer();
- stage.add(layer);
- // create shape
- var box = new Konva.Rect({
- x: 50,
- y: 50,
- width: 100,
- height: 50,
- fill: '#00D2FF',
- stroke: 'black',
- strokeWidth: 4,
- draggable: true,
- });
- layer.add(box);
- // add cursor styling
- box.on('mouseover', function () {
- document.body.style.cursor = 'pointer';
- });
- box.on('mouseout', function () {
- document.body.style.cursor = 'default';
- });
- </script>
- ```
Browsers support
Konva works in all modern mobile and desktop browsers. A browser need to be capable to run javascript code from ES2015 spec. For older browsers you may need polyfills for missing functions.
At the current moment Konva doesn't work in IE11 directly. To make it work you just need to provide some polyfills such as Array.prototype.find, String.prototype.trimLeft, String.prototype.trimRight, Array.from.
Loading and installing Konva
Konva supports UMD loading. So you can use all possible variants to load the framework into your project: