-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightboxSlider.svelte
119 lines (98 loc) · 1.96 KB
/
lightboxSlider.svelte
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script>
export let images;
$: activeImage = 0;
let active;
function showImg(e) {
activeImage = e;
active = 1;
}
function changeImg(e) {
let i = images.length;
if (e == 1) {
if (activeImage == 0) activeImage = i - 1;
else activeImage -= 1;
} else {
if (i == activeImage + 1) activeImage = 0;
else activeImage += 1;
}
}
</script>
{#if images}
{#if active}
<div id="overlay" class="grid cell">
<div id="overlayImage" class="rel">
<img class="bgw" src={images[activeImage].image} alt={images[activeImage].alt}/>
<button class="abs arrow arrowLeft white noBor" on:click={() => changeImg(1)}>‹</button>
<button class="abs arrow arrowRight white noBor" on:click={() => changeImg(2)}>›</button>
<button id="close" class="abs bold bgw" on:click={() => (active = '')}>X</button>
</div>
</div>
{/if}
<div id="img">
<div id="bigImg">
<img src={images[0]} alt={title} on:click={() => showImg(0)}/>
</div>
{#if images[1]}
<div id="mini" class="grid">
{#each images as item, i}
{#if i > 0}
<img src={item} alt={title} on:click={() => showImg(i)}/>
{/if}
{/each}
</div>
{/if}
</div>
{/if}
<style>
#overlay {
display: grid;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: 1350;
background-color: rgba(255,255,255,.8)
}
#overlay img,
#overlay #close { border: 1px solid #999 }
#overlay img {
max-height: 95vh;
padding: .5rem
}
#overlay button {
z-index: 2000
}
#overlay #close {
top: 1rem;
right: 1rem;
width: 32px;
height: 32px;
font-size: 1.2rem
}
#overlay .arrow {
top: 0;
width: 70px;
height: 100%;
font-size: 7rem
}
#overlay .arrowLeft { left: 0 }
#overlay .arrowRight { right: 0 }
button,
#product img { cursor: pointer }
.rel {
position: relative
}
.abs {
position: absolute
}
.bgw {
background-color: #fff
}
.white {
color: #fff
}
.noBor {
background-color: transparent
}
</style>