笔画

获取Konva最新的信息

我们可以在创建图形时设置 strokestrokeWidth 属性设置图形的笔画颜色和笔画宽度,图形创建后也可以使用 stroke()strokeWidth() 方法来修改。

说明:试试鼠标滑过每个五角星来改变它们的笔画颜色和宽度。

Konva Stroke Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@4.0.18/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Stroke Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
var layer = new Konva.Layer();

var pentagon = new Konva.RegularPolygon({
x: stage.width() / 2,
y: stage.height() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
});

pentagon.on('mouseover', function() {
this.stroke('blue');
this.strokeWidth(20);
layer.draw();
});

pentagon.on('mouseout', function() {
this.stroke('black');
this.strokeWidth(4);
layer.draw();
});
// add the shape to the layer
layer.add(pentagon);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>