forked from HDInnovations/UNIT3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposterRow.js
69 lines (63 loc) · 2.33 KB
/
posterRow.js
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
document.addEventListener('alpine:init', () => {
Alpine.data('posterRow', () => ({
tab: null,
init() {
this.tab = this.$root.dataset.defaultTab;
},
getPosterRow() {
let panel = this.$el.closest('.panelV2');
let posterRows = panel.querySelectorAll('[x-ref="posters"]');
let posterRow = [...posterRows].find((el) => el.checkVisibility());
return posterRow;
},
scrollLeft: {
['x-on:click.prevent']() {
let posterRow = this.getPosterRow();
let scrollBy = posterRow.offsetWidth / 2;
let currentScroll = posterRow.scrollLeft;
let maxScroll = posterRow.scrollWidth - posterRow.offsetWidth;
if (currentScroll == 0) {
posterRow.scrollTo({
left: maxScroll,
behavior: 'smooth',
});
} else if (currentScroll < scrollBy) {
posterRow.scrollTo({
left: 0,
behavior: 'smooth',
});
} else {
posterRow.scrollBy({
left: -1 * scrollBy,
behavior: 'smooth',
});
}
},
},
scrollRight: {
['x-on:click.prevent']() {
let posterRow = this.getPosterRow();
let scrollBy = posterRow.offsetWidth / 2;
let currentScroll = posterRow.scrollLeft;
let maxScroll = posterRow.scrollWidth - posterRow.offsetWidth;
let remainingScroll = maxScroll - currentScroll;
if (remainingScroll == 0) {
posterRow.scrollTo({
left: 0,
behavior: 'smooth',
});
} else if (remainingScroll < scrollBy) {
posterRow.scrollTo({
left: maxScroll,
behavior: 'smooth',
});
} else {
posterRow.scrollBy({
left: scrollBy,
behavior: 'smooth',
});
}
},
},
}));
});