mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
90 lines
2.4 KiB
HTML
90 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>KonvaJS Sandbox</title>
|
|
<meta
|
|
name="viewport"
|
|
content="width=device-width, initial-scale=1.0, user-scalable=1.0, minimum-scale=1.0, maximum-scale=1.0"
|
|
/>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
}
|
|
</style>
|
|
<!-- <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script> -->
|
|
<script>
|
|
// TouchEmulator();
|
|
</script>
|
|
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.7/hammer.js"></script> -->
|
|
<!-- <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script> -->
|
|
<!-- <script src="./hammer.js"></script> -->
|
|
<!-- <script src="https://unpkg.com/fabric@5.2.1/dist/fabric.js"></script> -->
|
|
</head>
|
|
|
|
<body>
|
|
<div id="container" style="background-color: bisque"></div>
|
|
|
|
<script type="module">
|
|
import Konva from '../src/index.ts';
|
|
|
|
const stage = new Konva.Stage({
|
|
container: 'container',
|
|
width: window.innerWidth / 2,
|
|
height: window.innerHeight / 2,
|
|
});
|
|
const layer = new Konva.Layer();
|
|
stage.add(layer);
|
|
const rect = new Konva.Rect({
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
fill: 'red',
|
|
});
|
|
layer.add(rect);
|
|
stage.on('wheel', (e) => {
|
|
e.evt.preventDefault();
|
|
console.log('wheel');
|
|
});
|
|
stage.on('contextmenu', (e) => {
|
|
console.log('click');
|
|
});
|
|
|
|
var imageObj = new Image();
|
|
imageObj.onload = function () {
|
|
var yoda = new Konva.Image({
|
|
x: 150,
|
|
y: 50,
|
|
image: imageObj,
|
|
width: 200,
|
|
height: 200,
|
|
draggable: true,
|
|
strokeWidth: 4,
|
|
stroke: 'blue',
|
|
cornerRadius: [10, 20, 30, 40],
|
|
});
|
|
layer.add(yoda);
|
|
};
|
|
imageObj.src = 'https://konvajs.org/assets/yoda.jpg';
|
|
|
|
Konva.Image.fromURL('https://konvajs.org/assets/darth-vader.jpg', function (darthNode) {
|
|
darthNode.setAttrs({
|
|
x: 300,
|
|
y: 50,
|
|
// scaleX: 0.5,
|
|
// scaleY: 0.5,
|
|
draggable: true,
|
|
strokeEnabled: true,
|
|
stroke: 'green',
|
|
strokeWidth: 2,
|
|
cornerRadius: 30,
|
|
});
|
|
layer.add(darthNode);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|