-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageSlider.html
129 lines (101 loc) · 3.02 KB
/
imageSlider.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
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
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*,
*::after,
*::before {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100vh;
width: 100%;
}
html {
color-scheme: light dark;
}
.center {
align-items: center;
background: #141414;
}
.wrapper {
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
background: #141414;
}
.container {
height: 400px;
aspect-ratio: 1.5/1;
display: flex;
overflow: hidden;
}
.container:has(.img.active) .img:not(.active) {
filter: grayscale(100%);
}
.img {
display: flex;
height: 100%;
width: 100%;
position: relative;
gap: 10px;
}
img {
height: 100%;
width: calc(100%/5);
object-fit: cover;
overflow: hidden;
border: 2px solid #141414;
transition: all 0.3s cubic-bezier(0.32, 0, 0.67, 0);
cursor: pointer;
}
.active {
width: 300%;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container">
<img class="img" src="images/walls.jpg" data-img=" images/walls.jpg">
<img class="img" src="images/space/gallexy1.jpg">
<img class="img" src="images/space/effect1.jpg">
<img class="img" src="images/dragIMG.jpg" alt="" data-img="images/dragIMG.jpg">
<img class="img" src="images/green-gallary/green-disk.jpg" alt="" data-img=" images/dragIMG.jpg">
</div>
</div>
<script>
const imgs = document.querySelectorAll('.img')
function clearActiveImg() {
imgs.forEach(function (img) {
img.classList.remove('active');
})
}
imgs.forEach(function (img, index) {
img.onclick = function () {
event.stopPropagation()
if (imgs[index].classList.contains('active')) {
imgs[index].classList.remove('active')
}
else {
clearActiveImg(index);
imgs[index].classList.add('active')
}
}
})
window.addEventListener('click', () => { clearActiveImg() })
imgs.forEach(function (img, index) {
setInterval(() => {
imgs[index].classList.remove('active')
}, 7000);
})
</script>
</body>
</html>