-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (42 loc) · 1.4 KB
/
script.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
let totalImages = 9; // available images
let carouselItemTemplate = (item) => {
let wrapper = document.createElement('div');
wrapper.classList.add('carousel-item');
wrapper.classList.add('shadow-lg');
let image = document.createElement('img');
image.src = `./collections/${item}.jpg`;
image.classList.add('img-fluid');
image.alt = "An image of iron man";
wrapper.appendChild(image);
return wrapper
};
let i = 1;
let fragment = document.createDocumentFragment()
while (i <= totalImages) {
fragment.append(carouselItemTemplate(i));
i++;
}
fragment.children[0].classList.add('active')
document.getElementById('carousel').appendChild(fragment);
// initialize carousel
$('.carousel').carousel();
// slide events
document.querySelectorAll('.controllers').forEach((item) => {
item.addEventListener('click', (e) => {
let direction = e.currentTarget.dataset['slide'];
$('.carousel').carousel(direction);
});
});
// fullscreen
document.getElementById('fullscreen').addEventListener('click', () => {
let elem = document.getElementById('carousel');
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
});