-
add(child) → {Container}
-
Add node or nodes to container.
Parameters:
Name |
Type |
Argument |
Description |
child |
Konva.Node
|
<repeatable>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Container
Example
layer.add(shape1, shape2, shape3);
-
-
add name to node
Parameters:
Name |
Type |
Description |
name |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.name('red');
node.addName('selected');
node.name(); // return 'red selected'
-
alpha(alpha) → {Float}
-
Parameters:
Name |
Type |
Description |
alpha |
Float
|
value between 0 and 1 |
- Inherited From:
- Source:
Returns:
-
Type
-
Float
-
blue(blue) → {Integer}
-
Parameters:
Name |
Type |
Description |
blue |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
blue(blue) → {Integer}
-
Parameters:
Name |
Type |
Description |
blue |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
blurRadius(radius) → {Integer}
-
Parameters:
Name |
Type |
Description |
radius |
Integer
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
brightness(brightness) → {Number}
-
get/set filter brightness. The brightness is a number between -1 and 1. Positive values
brighten the pixels and negative values darken them. Use with
Konva.Filters.Brighten filter.
Parameters:
Name |
Type |
Description |
brightness |
Number
|
value between -1 and 1 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
-
cache node to improve drawing performance, apply filters, or create more accurate
hit regions. For all basic shapes size of cache canvas will be automatically detected.
If you need to cache your custom `Konva.Shape` instance you have to pass shape's bounding box
properties. Look at [link to demo page](link to demo page) for more information.
Parameters:
Name |
Type |
Argument |
Description |
config |
Object
|
<optional>
|
Properties
Name |
Type |
Argument |
Description |
x |
Number
|
<optional>
|
|
y |
Number
|
<optional>
|
|
width |
Number
|
<optional>
|
|
height |
Number
|
<optional>
|
|
offset |
Number
|
<optional>
|
increase canvas size by `offset` pixel in all directions. |
drawBorder |
Boolean
|
<optional>
|
when set to true, a red border will be drawn around the cached
region for debugging purposes |
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// cache a shape with the x,y position of the bounding box at the center and
// the width and height of the bounding box equal to the width and height of
// the shape obtained from shape.width() and shape.height()
image.cache();
// cache a node and define the bounding box position and size
node.cache({
x: -30,
y: -30,
width: 100,
height: 200
});
// cache a node and draw a red border around the bounding box
// for debugging purposes
node.cache({
x: -30,
y: -30,
width: 100,
height: 200,
offset : 10,
drawBorder: true
});
-
clear(bounds)
-
clear scene and hit canvas contexts tied to the layer
Parameters:
Name |
Type |
Argument |
Description |
bounds |
Object
|
<optional>
|
Properties
Name |
Type |
Argument |
Description |
x |
Number
|
<optional>
|
|
y |
Number
|
<optional>
|
|
width |
Number
|
<optional>
|
|
height |
Number
|
<optional>
|
|
|
- Inherited From:
- Source:
Example
layer.clear();
layer.clear({
x : 0,
y : 0,
width : 100,
height : 100
});
-
clearBeforeDraw(clearBeforeDraw) → {Boolean}
-
get/set clearBeforeDraw flag which determines if the layer is cleared or not
before drawing
Parameters:
Name |
Type |
Description |
clearBeforeDraw |
Boolean
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
Example
// get clearBeforeDraw flag
var clearBeforeDraw = layer.clearBeforeDraw();
// disable clear before draw
layer.clearBeforeDraw(false);
// enable clear before draw
layer.clearBeforeDraw(true);
-
-
clear cached canvas
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.clearCache();
-
clip(clip) → {Object}
-
get/set clip
Parameters:
Name |
Type |
Description |
clip |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
width |
Number
|
|
height |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get clip
var clip = container.clip();
// set clip
container.setClip({
x: 20,
y: 20,
width: 20,
height: 20
});
-
clipHeight(height) → {Number}
-
get/set clip height
Parameters:
Name |
Type |
Description |
height |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get clip height
var clipHeight = container.clipHeight();
// set clip height
container.clipHeight(100);
-
clipWidth(width) → {Number}
-
get/set clip width
Parameters:
Name |
Type |
Description |
width |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get clip width
var clipWidth = container.clipWidth();
// set clip width
container.clipWidth(100);
-
clipX(x) → {Number}
-
get/set clip x
Parameters:
Name |
Type |
Description |
x |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get clip x
var clipX = container.clipX();
// set clip x
container.clipX(10);
-
clipY(y) → {Number}
-
get/set clip y
Parameters:
Name |
Type |
Description |
y |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get clip y
var clipY = container.clipY();
// set clip y
container.clipY(10);
-
-
clone node. Returns a new Node instance with identical attributes. You can also override
the node properties with an object literal, enabling you to use an existing node as a template
for another node
Parameters:
Name |
Type |
Description |
obj |
Object
|
override attrs |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// simple clone
var clone = node.clone();
// clone a node and override the x position
var clone = rect.clone({
x: 5
});
-
destroy()
-
remove and destroy self
- Inherited From:
- Source:
Example
node.destroy();
-
destroyChildren()
-
destroy all children
- Inherited From:
- Source:
-
dragBoundFunc(dragBoundFunc) → {function}
-
get/set drag bound function. This is used to override the default
drag and drop position
Parameters:
Name |
Type |
Description |
dragBoundFunc |
function
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
function
Example
// get drag bound function
var dragBoundFunc = node.dragBoundFunc();
// create vertical drag and drop
node.dragBoundFunc(function(pos){
return {
x: this.getAbsolutePosition().x,
y: pos.y
};
});
-
dragDistance(distance) → {Number}
-
get/set drag distance
Parameters:
Name |
Type |
Description |
distance |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get drag distance
var dragDistance = node.dragDistance();
// set distance
// node starts dragging only if pointer moved more then 3 pixels
node.dragDistance(3);
// or set globally
Konva.dragDistance = 3;
-
draggable(draggable) → {Boolean}
-
get/set draggable flag
Parameters:
Name |
Type |
Description |
draggable |
Boolean
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
Example
// get draggable flag
var draggable = node.draggable();
// enable drag and drop
node.draggable(true);
// disable drag and drop
node.draggable(false);
-
-
draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
embossBlend(embossBlend) → {Boolean}
-
Parameters:
Name |
Type |
Description |
embossBlend |
Boolean
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
embossDirection(embossDirection) → {String}
-
Parameters:
Name |
Type |
Description |
embossDirection |
String
|
can be top-left, top, top-right, right, bottom-right, bottom, bottom-left or left
The default is top-left |
- Inherited From:
- Source:
Returns:
-
Type
-
String
-
embossStrength(level) → {Number}
-
Parameters:
Name |
Type |
Description |
level |
Number
|
between 0 and 1. Default is 0.5 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
embossWhiteLevel(embossWhiteLevel) → {Number}
-
Parameters:
Name |
Type |
Description |
embossWhiteLevel |
Number
|
between 0 and 1. Default is 0.5 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
enhance(amount) → {Float}
-
Parameters:
Name |
Type |
Description |
amount |
Float
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Float
-
filters(filters) → {Array}
-
get/set filters. Filters are applied to cached canvases
Parameters:
Name |
Type |
Description |
filters |
Array
|
array of filters |
- Inherited From:
- Source:
Returns:
-
Type
-
Array
Example
// get filters
var filters = node.filters();
// set a single filter
node.cache();
node.filters([Konva.Filters.Blur]);
// set multiple filters
node.cache();
node.filters([
Konva.Filters.Blur,
Konva.Filters.Sepia,
Konva.Filters.Invert
]);
-
find(selector) → {Collection}
-
return a
Konva.Collection of nodes that match the selector. Use '#' for id selections
and '.' for name selections. You can also select by type or class name. Pass multiple selectors
separated by a space.
Parameters:
Name |
Type |
Description |
selector |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Collection
Example
// select node with id foo
var node = stage.find('#foo');
// select nodes with name bar inside layer
var nodes = layer.find('.bar');
// select all groups inside layer
var nodes = layer.find('Group');
// select all rectangles inside layer
var nodes = layer.find('Rect');
// select node with an id of foo or a name of bar inside layer
var nodes = layer.find('#foo, .bar');
-
findAncestor(selector, includeSelf, stopNode) → {Konva.Node}
-
get ancestor (parent or parent of the parent, etc) of the node that match passed selector
Parameters:
Name |
Type |
Argument |
Description |
selector |
String
|
<optional>
|
selector for search |
includeSelf |
Boolean
|
<optional>
|
show we think that node is ancestro itself? |
stopNode |
Konva.Node
|
<optional>
|
optional node where we need to stop searching (one of ancestors) |
- Inherited From:
- Source:
Returns:
ancestor
-
Type
-
Konva.Node
Example
// get one of the parent group
var group = node.findAncestors('.mygroup');
-
findAncestors(selector, includeSelf, stopNode) → {Array}
-
get all ancestros (parent then parent of the parent, etc) of the node
Parameters:
Name |
Type |
Argument |
Description |
selector |
String
|
<optional>
|
selector for search |
includeSelf |
Boolean
|
<optional>
|
show we think that node is ancestro itself? |
stopNode |
Konva.Node
|
<optional>
|
optional node where we need to stop searching (one of ancestors) |
- Inherited From:
- Source:
Returns:
[ancestors]
-
Type
-
Array
Example
// get one of the parent group
var parentGroups = node.findAncestors('Group');
-
findOne(selector) → {Konva.Node}
-
return a first node from `find` method
Parameters:
Name |
Type |
Description |
selector |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// select node with id foo
var node = stage.findOne('#foo');
// select node with name bar inside layer
var nodes = layer.findOne('.bar');
-
fire(eventType, evt, bubble) → {Konva.Node}
-
fire event
Parameters:
Name |
Type |
Argument |
Description |
eventType |
String
|
|
event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent |
evt |
Event
|
<optional>
|
event object |
bubble |
Boolean
|
<optional>
|
setting the value to false, or leaving it undefined, will result in the event
not bubbling. Setting the value to true will result in the event bubbling. |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// manually fire click event
node.fire('click');
// fire custom event
node.fire('foo');
// fire custom event with custom event object
node.fire('foo', {
bar: 10
});
// fire click event that bubbles
node.fire('click', null, true);
-
getAbsoluteOpacity() → {Number}
-
get absolute opacity
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
getAbsolutePosition(top) → {Object}
-
get absolute position relative to the top left corner of the stage container div
or relative to passed node
Parameters:
Name |
Type |
Argument |
Description |
top |
Object
|
<optional>
|
optional parent node |
- Inherited From:
- Source:
Returns:
-
Type
-
Object
-
-
get absolute transform of the node which takes into
account its ancestor transforms
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Transform
-
getAbsoluteZIndex() → {Integer}
-
get absolute z-index which takes into account sibling
and ancestor indices
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
getAllIntersections(pos) → {Array}
-
get all shapes that intersect a point. Note: because this method must clear a temporary
canvas and redraw every shape inside the container, it should only be used for special sitations
because it performs very poorly. Please use the
Konva.Stage#getIntersection method if at all possible
because it performs much better
Parameters:
Name |
Type |
Description |
pos |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
array of shapes
-
Type
-
Array
-
-
get ancestors
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Collection
Example
shape.getAncestors().each(function(node) {
console.log(node.getId());
})
-
getAttr(attr) → {Integer|String|Object|Array}
-
get attr
Parameters:
Name |
Type |
Description |
attr |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
|
String
|
Object
|
Array
Example
var x = node.getAttr('x');
-
getAttrs() → {Object}
-
get attrs object literal
- Inherited From:
- Source:
Returns:
-
Type
-
Object
-
getCanvas()
-
get layer canvas
- Inherited From:
- Source:
-
-
Parameters:
Name |
Type |
Argument |
Description |
filterFunc |
function
|
<optional>
|
filter function |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Collection
Example
// get all children
var children = layer.getChildren();
// get only circles
var circles = layer.getChildren(function(node){
return node.getClassName() === 'Circle';
});
-
getClassName() → {String}
-
get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.
- Inherited From:
- Source:
Returns:
-
Type
-
String
-
getClientRect(skipTransform) → {Object}
-
Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
The rectangle position is relative to parent container.
Parameters:
Name |
Type |
Argument |
Description |
skipTransform |
Boolean
|
<optional>
|
flag should we skip transformation to rectangle |
- Inherited From:
- Source:
Returns:
rect with {x, y, width, height} properties
-
Type
-
Object
Example
var rect = new Konva.Rect({
width : 100,
height : 100,
x : 50,
y : 50,
strokeWidth : 4,
stroke : 'black',
offsetX : 50,
scaleY : 2
});
// get client rect without think off transformations (position, rotation, scale, offset, etc)
rect.getClientRect(true);
// returns {
// x : -2, // two pixels for stroke / 2
// y : -2,
// width : 104, // increased by 4 for stroke
// height : 104
//}
// get client rect with transformation applied
rect.getClientRect();
// returns Object {x: -2, y: 46, width: 104, height: 208}
-
getContext()
-
get layer canvas context
- Inherited From:
- Source:
-
getDepth() → {Integer}
-
get node depth in node tree. Returns an integer.
e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
be >= 2
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
getHitCanvas()
-
get layer hit canvas
- Inherited From:
- Source:
-
-
get layer ancestor
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Layer
-
-
get parent container
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
getSelfRect() → {Object}
-
return self rectangle (x, y, width, height) of shape.
This method are not taken into account transformation and styles.
- Inherited From:
- Source:
Returns:
rect with {x, y, width, height} properties
-
Type
-
Object
Example
rect.getSelfRect(); // return {x:0, y:0, width:rect.width(), height:rect.height()}
circle.getSelfRect(); // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
-
-
get stage ancestor
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Stage
-
-
get transform of the node
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Transform
-
getType() → {String}
-
get the node type, which may return Stage, Layer, Group, or Node
- Inherited From:
- Source:
Returns:
-
Type
-
String
-
getZIndex() → {Integer}
-
get zIndex relative to the node's siblings who share the same parent
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
green(green) → {Integer}
-
Parameters:
Name |
Type |
Description |
green |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
green(green) → {Integer}
-
Parameters:
Name |
Type |
Description |
green |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
hasChildren() → {Boolean}
-
determine if node has children
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
hasName(name) → {Boolean}
-
check is node has name
Parameters:
Name |
Type |
Description |
name |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
Example
node.name('red');
node.hasName('red'); // return true
node.hasName('selected'); // return false
-
height() → {Number}
-
get/set height of layer.getter return height of stage. setter doing nothing.
if you want change height use `stage.height(value);`
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
var height = layer.height();
-
-
hide node. Hidden nodes are no longer detectable
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
hue(hue) → {Number}
-
Parameters:
Name |
Type |
Description |
hue |
Number
|
value between 0 and 359 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
hue(hue) → {Number}
-
Parameters:
Name |
Type |
Description |
hue |
Number
|
value between 0 and 359 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
id(id) → {String}
-
get/set id. Id is global for whole page.
Parameters:
Name |
Type |
Description |
id |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
String
Example
// get id
var name = node.id();
// set id
node.id('foo');
-
isAncestorOf(node)
-
determine if node is an ancestor
of descendant
Parameters:
- Inherited From:
- Source:
-
isDragging()
-
determine if node is currently in drag and drop mode
- Inherited From:
- Source:
-
isListening() → {Boolean}
-
determine if node is listening for events by taking into account ancestors.
Parent | Self | isListening
listening | listening |
----------+-----------+------------
T | T | T
T | F | F
F | T | T
F | F | F
----------+-----------+------------
T | I | T
F | I | F
I | I | T
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
isVisible() → {Boolean}
-
determine if node is visible by taking into account ancestors.
Parent | Self | isVisible
visible | visible |
----------+-----------+------------
T | T | T
T | F | F
F | T | T
F | F | F
----------+-----------+------------
T | I | T
F | I | F
I | I | T
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
kaleidoscopeAngle(degrees) → {Integer}
-
get/set kaleidoscope angle. Use with Konva.Filters.Kaleidoscope filter.
Parameters:
Name |
Type |
Description |
degrees |
Integer
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
kaleidoscopePower(power) → {Integer}
-
get/set kaleidoscope power. Use with Konva.Filters.Kaleidoscope filter.
Parameters:
Name |
Type |
Description |
power |
Integer
|
of kaleidoscope |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
levels(level) → {Number}
-
Parameters:
Name |
Type |
Description |
level |
Number
|
between 0 and 1 |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
listening(listening) → {Boolean|String}
-
get/set listenig attr. If you need to determine if a node is listening or not
by taking into account its parents, use the isListening() method
Parameters:
Name |
Type |
Description |
listening |
Boolean
|
String
|
Can be "inherit", true, or false. The default is "inherit". |
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
|
String
Example
// get listening attr
var listening = node.listening();
// stop listening for events
node.listening(false);
// listen for events
node.listening(true);
// listen to events according to the parent
node.listening('inherit');
-
-
move node by an amount relative to its current position
Parameters:
Name |
Type |
Description |
change |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// move node in x direction by 1px and y direction by 2px
node.move({
x: 1,
y: 2)
});
-
moveDown() → {Boolean}
-
move node down
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
moveTo(newContainer) → {Konva.Node}
-
move node to another container
Parameters:
Name |
Type |
Description |
newContainer |
Container
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// move node from current layer into layer2
node.moveTo(layer2);
-
moveToBottom() → {Boolean}
-
move node to the bottom of its siblings
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
moveToTop() → {Boolean}
-
move node to the top of its siblings
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
moveUp() → {Boolean}
-
move node up
- Inherited From:
- Source:
Returns:
flag is moved or not
-
Type
-
Boolean
-
name(name) → {String}
-
get/set name
Parameters:
Name |
Type |
Description |
name |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
String
Example
// get name
var name = node.name();
// set name
node.name('foo');
// also node may have multiple names (as css classes)
node.name('foo bar');
-
noise(noise) → {Number}
-
Parameters:
Name |
Type |
Description |
noise |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
-
remove event bindings from the node. Pass in a string of
event types delimmited by a space to remove multiple event
bindings at once such as 'mousedown mouseup mousemove'.
include a namespace to remove an event binding by name
such as 'click.foobar'. If you only give a name like '.foobar',
all events in that namespace will be removed.
Parameters:
Name |
Type |
Description |
evtStr |
String
|
e.g. 'click', 'mousedown touchstart', '.foobar' |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// remove listener
node.off('click');
// remove multiple listeners
node.off('click touchstart');
// remove listener by name
node.off('click.foo');
-
offsetX(x) → {Number}
-
get/set offset x
Parameters:
Name |
Type |
Description |
x |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get offset x
var offsetX = node.offsetX();
// set offset x
node.offsetX(3);
-
offsetY(y) → {Number}
-
get/set offset y
Parameters:
Name |
Type |
Description |
y |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get offset y
var offsetY = node.offsetY();
// set offset y
node.offsetY(3);
-
on(evtStr, handler) → {Konva.Node}
-
bind events to the node. KonvaJS supports mouseover, mousemove,
mouseout, mouseenter, mouseleave, mousedown, mouseup, mousewheel, click, dblclick, touchstart, touchmove,
touchend, tap, dbltap, dragstart, dragmove, and dragend events. The Konva Stage supports
contentMouseover, contentMousemove, contentMouseout, contentMousedown, contentMouseup,
contentClick, contentDblclick, contentTouchstart, contentTouchmove, contentTouchend, contentTap,
and contentDblTap. Pass in a string of events delimmited by a space to bind multiple events at once
such as 'mousedown mouseup mousemove'. Include a namespace to bind an
event by name such as 'click.foobar'.
Parameters:
Name |
Type |
Description |
evtStr |
String
|
e.g. 'click', 'mousedown touchstart', 'mousedown.foo touchstart.foo' |
handler |
function
|
The handler function is passed an event object |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
// add click listener
node.on('click', function() {
console.log('you clicked me!');
});
// get the target node
node.on('click', function(evt) {
console.log(evt.target);
});
// stop event propagation
node.on('click', function(evt) {
evt.cancelBubble = true;
});
// bind multiple listeners
node.on('click touchstart', function() {
console.log('you clicked/touched me!');
});
// namespace listener
node.on('click.foo', function() {
console.log('you clicked/touched me!');
});
// get the event type
node.on('click tap', function(evt) {
var eventType = evt.type;
});
// get native event object
node.on('click tap', function(evt) {
var nativeEvent = evt.evt;
});
// for change events, get the old and new val
node.on('xChange', function(evt) {
var oldVal = evt.oldVal;
var newVal = evt.newVal;
});
// get event targets
// with event delegations
layer.on('click', 'Group', function(evt) {
var shape = evt.target;
var group = evtn.currentTarger;
});
-
opacity(opacity) → {Number}
-
get/set opacity. Opacity values range from 0 to 1.
A node with an opacity of 0 is fully transparent, and a node
with an opacity of 1 is fully opaque
Parameters:
Name |
Type |
Description |
opacity |
Object
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get opacity
var opacity = node.opacity();
// set opacity
node.opacity(0.5);
-
pixelSize(pixelSize) → {Integer}
-
Parameters:
Name |
Type |
Description |
pixelSize |
Integer
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
position(pos) → {Object}
-
get/set node position relative to parent
Parameters:
Name |
Type |
Description |
pos |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get position
var position = node.position();
// set position
node.position({
x: 5
y: 10
});
-
red(red) → {Integer}
-
Parameters:
Name |
Type |
Description |
red |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
red(red) → {Integer}
-
Parameters:
Name |
Type |
Description |
red |
Integer
|
value between 0 and 255 |
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
-
-
remove self from parent, but don't destroy
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.remove();
-
removeChildren()
-
remove all children
- Inherited From:
- Source:
-
removeName(name) → {Konva.Node}
-
remove name from node
Parameters:
Name |
Type |
Description |
name |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.name('red selected');
node.removeName('selected');
node.hasName('selected'); // return false
node.name(); // return 'red'
-
-
rotate node by an amount in degrees relative to its current rotation
Parameters:
Name |
Type |
Description |
theta |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
rotation(rotation) → {Number}
-
get/set rotation in degrees
Parameters:
Name |
Type |
Description |
rotation |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get rotation in degrees
var rotation = node.rotation();
// set rotation in degrees
node.rotation(45);
-
saturation(saturation) → {Number}
-
Parameters:
Name |
Type |
Description |
saturation |
Number
|
0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
saturation(saturation) → {Number}
-
Parameters:
Name |
Type |
Description |
saturation |
Number
|
0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
scale(scale) → {Object}
-
get/set scale
Parameters:
Name |
Type |
Description |
scale |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get scale
var scale = node.scale();
// set scale
shape.scale({
x: 2
y: 3
});
-
scaleX(x) → {Number}
-
get/set scale x
Parameters:
Name |
Type |
Description |
x |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get scale x
var scaleX = node.scaleX();
// set scale x
node.scaleX(2);
-
scaleY(y) → {Number}
-
get/set scale y
Parameters:
Name |
Type |
Description |
y |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get scale y
var scaleY = node.scaleY();
// set scale y
node.scaleY(2);
-
setAbsolutePosition(pos) → {Konva.Node}
-
set absolute position
Parameters:
Name |
Type |
Description |
pos |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
setAttr(attr, val) → {Konva.Node}
-
set attr
Parameters:
Name |
Type |
Description |
attr |
String
|
|
val |
*
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.setAttr('x', 5);
-
setAttrs(config) → {Konva.Node}
-
set multiple attrs at once using an object literal
Parameters:
Name |
Type |
Description |
config |
Object
|
object containing key value pairs |
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
Example
node.setAttrs({
x: 5,
fill: 'red'
});
-
setZIndex(zIndex) → {Konva.Node}
-
set zIndex relative to siblings
Parameters:
Name |
Type |
Description |
zIndex |
Integer
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
shouldDrawHit() → {Boolean}
-
determine if listening is enabled by taking into account descendants. If self or any children
have _isListeningEnabled set to true, then self also has listening enabled.
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
-
-
show node
- Inherited From:
- Source:
Returns:
-
Type
-
Konva.Node
-
size(size) → {Object}
-
get/set node size
Parameters:
Name |
Type |
Description |
size |
Object
|
Properties
Name |
Type |
Description |
width |
Number
|
|
height |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get node size
var size = node.size();
var x = size.x;
var y = size.y;
// set size
node.size({
width: 100,
height: 200
});
-
skew(skew) → {Object}
-
get/set skew
Parameters:
Name |
Type |
Description |
skew |
Object
|
Properties
Name |
Type |
Description |
x |
Number
|
|
y |
Number
|
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get skew
var skew = node.skew();
// set skew
node.skew({
x: 20
y: 10
});
-
skewX(x) → {Number}
-
get/set skew x
Parameters:
Name |
Type |
Description |
x |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get skew x
var skewX = node.skewX();
// set skew x
node.skewX(3);
-
skewY(y) → {Number}
-
get/set skew y
Parameters:
Name |
Type |
Description |
y |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
// get skew y
var skewY = node.skewY();
// set skew y
node.skewY(3);
-
startDrag()
-
initiate drag and drop
- Inherited From:
- Source:
-
stopDrag()
-
stop drag and drop
- Inherited From:
- Source:
-
threshold(threshold) → {Number}
-
Parameters:
Name |
Type |
Description |
threshold |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
to(params)
-
Tween node properties. Shorter usage of
Konva.Tween object.
Parameters:
Name |
Type |
Argument |
Description |
params |
Object
|
<optional>
|
tween params |
- Inherited From:
- Source:
Example
circle.to({
x : 50,
duration : 0.5
});
-
toDataURL(config) → {String}
-
Creates a composite data URL. If MIME type is not
specified, then "image/png" will result. For "image/jpeg", specify a quality
level as quality (range 0.0 - 1.0)
Parameters:
Name |
Type |
Description |
config |
Object
|
Properties
Name |
Type |
Argument |
Description |
mimeType |
String
|
<optional>
|
can be "image/png" or "image/jpeg".
"image/png" is the default |
x |
Number
|
<optional>
|
x position of canvas section |
y |
Number
|
<optional>
|
y position of canvas section |
width |
Number
|
<optional>
|
width of canvas section |
height |
Number
|
<optional>
|
height of canvas section |
quality |
Number
|
<optional>
|
jpeg quality. If using an "image/jpeg" mimeType,
you can specify the quality from 0 to 1, where 0 is very poor quality and 1
is very high quality |
|
- Inherited From:
- Source:
Returns:
-
Type
-
String
-
toImage(config)
-
converts node into an image. Since the toImage
method is asynchronous, a callback is required. toImage is most commonly used
to cache complex drawings as an image so that they don't have to constantly be redrawn
Parameters:
Name |
Type |
Description |
config |
Object
|
Properties
Name |
Type |
Argument |
Description |
callback |
function
|
|
function executed when the composite has completed |
mimeType |
String
|
<optional>
|
can be "image/png" or "image/jpeg".
"image/png" is the default |
x |
Number
|
<optional>
|
x position of canvas section |
y |
Number
|
<optional>
|
y position of canvas section |
width |
Number
|
<optional>
|
width of canvas section |
height |
Number
|
<optional>
|
height of canvas section |
quality |
Number
|
<optional>
|
jpeg quality. If using an "image/jpeg" mimeType,
you can specify the quality from 0 to 1, where 0 is very poor quality and 1
is very high quality |
|
- Inherited From:
- Source:
Example
var image = node.toImage({
callback: function(img) {
// do stuff with img
}
});
-
toJSON() → {String}
-
convert Node into a JSON string. Returns a JSON string.
- Inherited From:
- Source:
Returns:
}
-
Type
-
String
-
toObject() → {Object}
-
convert Node into an object for serialization. Returns an object.
- Inherited From:
- Source:
Returns:
-
Type
-
Object
-
-
get/set transforms that are enabled. Can be "all", "none", or "position". The default
is "all"
Parameters:
Name |
Type |
Description |
enabled |
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
String
Example
// enable position transform only to improve draw performance
node.transformsEnabled('position');
// enable all transforms
node.transformsEnabled('all');
-
value(value) → {Number}
-
Parameters:
Name |
Type |
Description |
value |
Number
|
0 is no change, -1.0 halves the value, 1.0 doubles, etc.. |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
value(value) → {Number}
-
Parameters:
Name |
Type |
Description |
value |
Number
|
0 is no change, -1.0 halves the value, 1.0 doubles, etc.. |
- Inherited From:
- Source:
Returns:
-
Type
-
Number
-
visible(visible) → {Boolean|String}
-
get/set visible attr. Can be "inherit", true, or false. The default is "inherit".
If you need to determine if a node is visible or not
by taking into account its parents, use the isVisible() method
Parameters:
Name |
Type |
Description |
visible |
Boolean
|
String
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Boolean
|
String
Example
// get visible attr
var visible = node.visible();
// make invisible
node.visible(false);
// make visible
node.visible(true);
// make visible according to the parent
node.visible('inherit');
-
width() → {Number}
-
get/set width of layer.getter return width of stage. setter doing nothing.
if you want change width use `stage.width(value);`
- Inherited From:
- Source:
Returns:
-
Type
-
Number
Example
var width = layer.width();
-
x(x) → {Object}
-
get/set x position
Parameters:
Name |
Type |
Description |
x |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Object
Example
// get x
var x = node.x();
// set x
node.x(5);
-
y(y) → {Integer}
-
get/set y position
Parameters:
Name |
Type |
Description |
y |
Number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
Integer
Example
// get y
var y = node.y();
// set y
node.y(5);