mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 09:50:05 +08:00
88 lines
2.7 KiB
HTML
88 lines
2.7 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;
|
|
}
|
|
body {
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
</style>
|
|
<!-- <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script> -->
|
|
<script src="https://unpkg.com/gifler@0.1.0/gifler.min.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"></div>
|
|
<textarea class="test" id="text">Hello</textarea>
|
|
|
|
<script type="module">
|
|
import Konva from '../src/index.ts';
|
|
|
|
var width = window.innerWidth;
|
|
var height = window.innerHeight;
|
|
|
|
var stage = new Konva.Stage({
|
|
container: 'container',
|
|
width: width,
|
|
height: height,
|
|
});
|
|
|
|
var layer = new Konva.Layer();
|
|
stage.add(layer);
|
|
|
|
const text = new Konva.Text({
|
|
text: 'Hello, how are you doing today? Would you like to start using konva.js',
|
|
width: 400,
|
|
fontSize: 50,
|
|
x: 100,
|
|
y: 100,
|
|
draggable: true,
|
|
});
|
|
layer.add(text);
|
|
|
|
const anim = new Konva.Animation((frame) => {
|
|
text.charRenderFunc(({ char, index, context }) => {
|
|
const animationDuration = 4000;
|
|
const animationTime = frame.time % animationDuration;
|
|
const length = text.text().length;
|
|
const durationPerChar = animationDuration / length;
|
|
const localStartTime = index * durationPerChar;
|
|
const localTime = animationTime - localStartTime;
|
|
const inAnimation = localTime > 0;
|
|
if (!inAnimation) {
|
|
context.setAttr('globalAlpha', 0);
|
|
return;
|
|
}
|
|
const afterAnimation = localTime > durationPerChar;
|
|
if (afterAnimation) {
|
|
return;
|
|
}
|
|
const animationAlpha = Math.abs(localTime / durationPerChar);
|
|
const oldOpacity = context.globalAlpha;
|
|
context.setAttr('globalAlpha', oldOpacity * animationAlpha * 0.5);
|
|
context.translate(0, -15 + (localTime / durationPerChar) * 15);
|
|
});
|
|
}, layer);
|
|
anim.start();
|
|
</script>
|
|
</body>
|
|
</html>
|