Skip to content

Commit de1207c

Browse files
committed
docs: Adding useRafFn advanced demo
1 parent e2fd7f7 commit de1207c

File tree

13 files changed

+135
-7
lines changed

13 files changed

+135
-7
lines changed

.storybook/configureStorybook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const basicTheme = create({
1010
base: 'light',
1111
brandTitle: '🛠️ Vue use kit',
1212
brandUrl: pkg.repository.url,
13-
brandImage: null
13+
brandImage: 'https://raw.githubusercontent.com/microcipcip/vue-use-kit/master/public/logo-storybook.png',
1414
})
1515

1616
addParameters({

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<br>
44
<a href="https://github.com/microcipcip/vue-use-kit">
55
<img
6-
src="https://raw.githubusercontent.com/microcipcip/vue-use-kit/master/assets/branding/logo.png"
6+
src="https://raw.githubusercontent.com/microcipcip/vue-use-kit/master/public/branding/logo.png"
77
alt="Vue use kit"
88
width="200"
99
/>

assets/branding/logo.png

-57 KB
Binary file not shown.

assets/branding/vue-use-kit.psd

-2.4 MB
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"prebuild": "rimraf dist && rimraf docs",
3131
"build": "tsc --module commonjs -p ./tsconfig.build.json && rollup -c rollup.config.ts && npm run storybook:build && npm run build:clean",
3232
"build:clean": "ts-node tools/build-clean",
33-
"dev": "start-storybook -p 3000",
34-
"storybook:build": "build-storybook --quiet -c .storybook -o docs",
33+
"dev": "start-storybook -p 3000 -s ./public",
34+
"storybook:build": "build-storybook --quiet -c .storybook -s ./public -o docs",
3535
"test": "jest --verbose",
3636
"test:staged": "jest --bail --findRelatedTests",
3737
"test:watch": "jest --watch",

public/branding/logo-storybook.png

1.36 KB
Loading

public/branding/logo.png

58.7 KB
Loading

public/branding/vue-use-kit.psd

2.67 MB
Binary file not shown.
File renamed without changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<template>
2+
<div class="box">
3+
<div
4+
class="sprite"
5+
style="background-image: url('/demo/muybridge.png')"
6+
:style="spriteStyle"
7+
></div>
8+
9+
<br />
10+
<div class="field">
11+
<button class="button" @click="stop" v-if="isRunning">
12+
<span class="icon"><i class="fas fa-pause"></i></span>
13+
</button>
14+
<button class="button" @click="start" v-else>
15+
<span class="icon"><i class="fas fa-play"></i></span>
16+
</button>
17+
<button class="button" @click="backward">
18+
<span class="icon"><i class="fas fa-backward"></i></span>
19+
</button>
20+
<button class="button" @click="forward">
21+
<span class="icon"><i class="fas fa-forward"></i></span>
22+
</button>
23+
</div>
24+
<div class="field">
25+
<label class="label">Frames per second (fps)</label>
26+
<div class="control">
27+
<input class="input" type="number" min="1" max="121" v-model="fps" />
28+
</div>
29+
</div>
30+
</div>
31+
</template>
32+
33+
<script lang="ts">
34+
import Vue from 'vue'
35+
import { ref, computed } from '../../../api'
36+
import { useRafFn } from '../../../vue-use-kit'
37+
38+
const spriteOpts = {
39+
w: 175 * 2, // Enlarge sprite 2x
40+
h: 130 * 2, // Enlarge sprite 2x
41+
frames: 16
42+
}
43+
44+
export default Vue.extend({
45+
name: 'UseRafFnAdvancedDemo',
46+
setup() {
47+
const fps = ref(16)
48+
const spriteDirection = ref(-1)
49+
const spriteCurrentFrame = ref(0)
50+
51+
let countFrame = 0
52+
const handleAnim = () => {
53+
// Get current frame
54+
spriteCurrentFrame.value = countFrame % spriteOpts.frames
55+
countFrame = countFrame + 1
56+
}
57+
58+
const spriteStyle = computed(() => {
59+
const posX =
60+
spriteOpts.w * spriteCurrentFrame.value * spriteDirection.value
61+
return {
62+
backgroundPosition: `${posX}px`
63+
}
64+
})
65+
66+
const backward = () => {
67+
spriteDirection.value = 1
68+
}
69+
70+
const forward = () => {
71+
spriteDirection.value = -1
72+
}
73+
74+
const { isRunning, start, stop } = useRafFn(handleAnim, fps)
75+
return { isRunning, start, stop, backward, forward, fps, spriteStyle }
76+
}
77+
})
78+
</script>
79+
80+
<style>
81+
.sprite {
82+
/* Enlarge sprite 2x */
83+
width: 350px;
84+
height: 260px;
85+
background-size: 5600px 260px;
86+
}
87+
</style>

0 commit comments

Comments
 (0)