page: 📄 common Easings

This commit is contained in:
bunny 2024-07-17 08:58:34 +08:00
parent 1fd9d75928
commit fbf929cc81
2 changed files with 103 additions and 1 deletions

View File

@ -1,5 +1,4 @@
```sh ```sh
https://konvajs.org/docs/tweens/Common_Easings.html
https://konvajs.org/docs/tweens/All_Easings.html https://konvajs.org/docs/tweens/All_Easings.html
https://konvajs.org/docs/tweens/All_Controls.html https://konvajs.org/docs/tweens/All_Controls.html
https://konvajs.org/docs/tweens/Tween_Filter.html https://konvajs.org/docs/tweens/Tween_Filter.html

View File

@ -0,0 +1,103 @@
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import Konva from 'konva/lib';
const { width, height } = useWindowSize();
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.draggable(true);
const layer = new Konva.Layer();
stage.add(layer);
const greenBox = new Konva.Rect({
x: 70,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});
const blueBox = new Konva.Rect({
x: 190,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'blue',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});
const redBox = new Konva.Rect({
x: 310,
y: stage.height() / 2,
width: 100,
height: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
offset: {
x: 50,
y: 25,
},
});
layer.add(greenBox);
layer.add(blueBox);
layer.add(redBox);
// the tween has to be created after the node has been added to the layer
greenBox.tween = new Konva.Tween({
node: greenBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseIn,
duration: 1,
});
blueBox.tween = new Konva.Tween({
node: blueBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseInOut,
duration: 1,
});
redBox.tween = new Konva.Tween({
node: redBox,
scaleX: 2,
scaleY: 1.5,
easing: Konva.Easings.EaseOut,
duration: 1,
});
// use event delegation
layer.on('mouseover touchstart', function (evt) {
evt.target.tween.play();
});
layer.on('mouseout touchend', function (evt) {
evt.target.tween.reverse();
});
};
onMounted(() => {
initial();
});
</script>
<template>
<div id="container"></div>
</template>
<style scoped lang="scss"></style>