-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo-vue3.html
52 lines (48 loc) · 1.03 KB
/
demo-vue3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue3-smooth-scroll</title>
<script src="https://unpkg.com/vue@next"></script>
<script src="./dist/vue-smooth-scroll.min.js"></script>
</head>
<body>
<div id="app"></div>
<script>
const app = Vue.createApp({
template: `<scroll-demo />`
})
app.use(VueSmoothScroll)
app.component('scroll-demo', {
template: `
<section id="first" ref="first">
<a href="#second" v-smooth-scroll>scrollDown</a>
</section>
<section id="second" ref="second">
<a href="#first" @click="toFirst">scrollUp</a>
</section>`,
setup () {
const smoothScroll = Vue.inject('smoothScroll')
const refs = Vue.reactive({
first: null,
second: null
})
const toFirst = () => {
smoothScroll({ scrollTo: refs.first })
}
return {
...Vue.toRefs(refs),
toFirst
}
}
})
app.mount('#app')
</script>
<style>
section {
height: 100vh;
}
</style>
</body>
</html>