HTML5 Canvas 箭头教程
要使用 Konva 创建箭头图形,可以实例化一个 Konva.Arrow() 对象。
有关完整的属性和方法列表,请参阅 Arrow API 参考。
- Vanilla
- React
- Vue
import Konva from 'konva';
const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});
const layer = new Konva.Layer();
stage.add(layer);
const arrow = new Konva.Arrow({
x: stage.width() / 4,
y: stage.height() / 4,
points: [0, 0, 100, 100],
pointerLength: 20,
pointerWidth: 20,
fill: 'black',
stroke: 'black',
strokeWidth: 4
});
layer.add(arrow);
import { Stage, Layer, Arrow } from 'react-konva';
const App = () => {
return (
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<Arrow
x={window.innerWidth / 4}
y={window.innerHeight / 4}
points={[0, 0, 100, 100]}
pointerLength={20}
pointerWidth={20}
fill="black"
stroke="black"
strokeWidth={4}
/>
</Layer>
</Stage>
);
};
export default App;
<template>
<v-stage :config="stageSize">
<v-layer>
<v-arrow :config="arrowConfig" />
</v-layer>
</v-stage>
</template>
<script setup>
const stageSize = {
width: window.innerWidth,
height: window.innerHeight
};
const arrowConfig = {
x: window.innerWidth / 4,
y: window.innerHeight / 4,
points: [0, 0, 100, 100],
pointerLength: 20,
pointerWidth: 20,
fill: 'black',
stroke: 'black',
strokeWidth: 4
};
</script>