forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageStripVertical.vue
More file actions
76 lines (67 loc) · 1.89 KB
/
ImageStripVertical.vue
File metadata and controls
76 lines (67 loc) · 1.89 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
<template>
<div class="q-pa-md">
<div class="q-gutter-y-sm" style="overflow-x: visible; overflow-y: auto; width: 300px; max-width: 20vw; max-height: 80vh">
<q-img
v-for="(src, index) in images"
:key="index"
:ref="el => { thumbRef[index] = el }"
class="cursor-pointer"
:class="index === indexZoomed ? 'fixed-top-right q-mr-md q-mt-md z-top' : void 0"
style="border-radius: 3%/5%;"
:style="index === indexZoomed ? 'width: 800px; max-width: 70vw;' : void 0"
:src="src"
@click="zoomImage(index)"
/>
</div>
</div>
</template>
<script>
import { ref, onBeforeUpdate } from 'vue'
import { morph } from 'quasar'
export default {
setup () {
const thumbRef = ref([])
const indexZoomed = ref(void 0)
const images = ref(Array(24).fill(null).map((_, i) => 'https://picsum.photos/id/' + i + '/500/300'))
function zoomImage (index) {
const indexZoomedState = indexZoomed.value
let cancel = void 0
indexZoomed.value = void 0
if (index !== void 0 && index !== indexZoomedState) {
cancel = morph({
from: thumbRef.value[ index ].$el,
onToggle: () => {
indexZoomed.value = index
},
duration: 500,
onEnd: end => {
if (end === 'from' && indexZoomed.value === index) {
indexZoomed.value = void 0
}
}
})
}
if (
indexZoomedState !== void 0 &&
(cancel === void 0 || cancel() === false)
) {
morph({
from: thumbRef.value[ indexZoomedState ].$el,
waitFor: 100,
duration: 300
})
}
}
// Make sure to reset the dynamic refs before each update.
onBeforeUpdate(() => {
thumbRef.value = []
})
return {
thumbRef,
indexZoomed,
images,
zoomImage
}
}
}
</script>