Konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d contex...

README

Konva logo

Konva

Financial Contributors on Open Collective npm version Build Status Build StatusCDNJS version

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.

- Visit: The Home Page and follow on Twitter

Quick Look


  1. ``` html
  2. <script src="https://unpkg.com/konva@8/konva.min.js"></script>
  3. <div id="container"></div>
  4. <script>
  5.   var stage = new Konva.Stage({
  6.     container: 'container',
  7.     width: window.innerWidth,
  8.     height: window.innerHeight,
  9.   });
  10.   // add canvas element
  11.   var layer = new Konva.Layer();
  12.   stage.add(layer);
  13.   // create shape
  14.   var box = new Konva.Rect({
  15.     x: 50,
  16.     y: 50,
  17.     width: 100,
  18.     height: 50,
  19.     fill: '#00D2FF',
  20.     stroke: 'black',
  21.     strokeWidth: 4,
  22.     draggable: true,
  23.   });
  24.   layer.add(box);
  25.   // add cursor styling
  26.   box.on('mouseover', function () {
  27.     document.body.style.cursor = 'pointer';
  28.   });
  29.   box.on('mouseout', function () {
  30.     document.body.style.cursor = 'default';
  31.   });
  32. </script>
  33. ```

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:

### Load Konva via classical `