forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSynchronized.vue
More file actions
102 lines (89 loc) · 2.33 KB
/
Synchronized.vue
File metadata and controls
102 lines (89 loc) · 2.33 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<div class="q-ma-md row no-wrap">
<q-scroll-area
visible
:thumb-style="thumbStyle"
:bar-style="barStyle"
style="height: 200px;"
class="col"
ref="firstRef"
@scroll="onScrollFirst"
>
<div v-for="n in 100" :key="n" class="q-pa-sm">
Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.
</div>
</q-scroll-area>
<q-scroll-area
visible
:thumb-style="thumbStyle"
:bar-style="barStyle"
style="height: 200px;"
class="col"
ref="secondRef"
@scroll="onScrollSecond"
>
<div v-for="n in 100" :key="n" class="q-pa-sm">
Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.
</div>
</q-scroll-area>
</div>
</template>
<script>
import { ref } from 'vue'
export default {
setup () {
const firstRef = ref(null)
const secondRef = ref(null)
let ignoreSource
function scroll (source, position) {
// if we previously just updated
// the scroll position, then ignore
// this update as otherwise we'll flicker
// the position from one scroll area to
// the other in an infinite loop
if (ignoreSource === source) {
ignoreSource = null
return
}
// we'll now update the other scroll area,
// which will also trigger a @scroll event...
// and we need to ignore that one
ignoreSource = source === 'first'
? 'second'
: 'first'
const areaRef = source === 'first'
? secondRef
: firstRef
areaRef.value.setScrollPosition('vertical', position)
}
return {
firstRef,
secondRef,
thumbStyle: {
right: '4px',
borderRadius: '7px',
backgroundColor: '#027be3',
width: '4px',
opacity: 0.75
},
barStyle: {
right: '2px',
borderRadius: '9px',
backgroundColor: '#027be3',
width: '8px',
opacity: 0.2
},
onScrollFirst ({ verticalPosition }) {
scroll('first', verticalPosition)
},
onScrollSecond ({ verticalPosition }) {
scroll('second', verticalPosition)
}
}
}
}
</script>