在创建图形时我们可以通过 lineJoin
设置边角,或者创建后通过 lineJoin()
方法修改。
lineJoin
可选值为:miter
(默认), bevel
, 和 round
。
说明:试试鼠标滑过三角形来改变它的边角样式。
Konva Line Join 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 Line Join 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 triangle = new Konva.RegularPolygon({ x: stage.width() / 2, y: stage.height() / 2, sides: 3, radius: 70, fill: 'red', stroke: 'black', strokeWidth: 20, lineJoin: 'bevel' });
triangle.on('mouseover', function() { this.lineJoin('round'); layer.draw(); });
triangle.on('mouseout', function() { this.lineJoin('bevel'); layer.draw(); });
layer.add(triangle);
stage.add(layer); </script> </body> </html>
|