-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
113 lines (93 loc) · 2.89 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
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
// get elements
let presentation = document.querySelector(".presentation");
// let slides = document.querySelectorAll(".slide");
// let currentSlide = document.querySelector(".slide.show");
let slides, currentSlide;
var slideNumber = document.querySelector(".counter");
var toLeftBtn = document.querySelector("#left-btn");
var toRightBtn = document.querySelector("#right-btn");
let presentationController = document.querySelector("#presentation-area");
var toFullScreenBtn = document.querySelector("#full-screen");
var toSmallScreenBtn = document.querySelector("#small-screen");
// initailize defualt values
var currentSlideNo = 1;
var totalSides = 0;
// keyboard input
document.addEventListener('keydown', (event) => {
var name = event.key;
if (name == "ArrowDown" || name == "ArrowRight") {
moveToRightSlide();
}
if (name == "ArrowUp" || name == "ArrowLeft") {
moveToLeftSlide();
}
}, false);
// run init script
init();
function init() {
fullScreenMode();
slides = document.querySelectorAll(".slide");
currentSlide = document.querySelector(".slide.show");
getCurrentSlideNo();
totalSides = slides.length;
setSlideNo();
hideLeftButton();
hideRightButton();
}
// handle clicks on left and right icons
toLeftBtn.addEventListener("click", moveToLeftSlide);
toRightBtn.addEventListener("click", moveToRightSlide);
// hide left button at first page
function hideLeftButton() {
if (currentSlideNo == 1) {
toLeftBtn.classList.remove("show");
} else {
toLeftBtn.classList.add("show");
}
}
// hide right button at last page
function hideRightButton() {
if (currentSlideNo === totalSides) {
toRightBtn.classList.remove("show");
} else {
toRightBtn.classList.add("show");
}
}
// moves to left slide
function moveToLeftSlide() {
if (currentSlideNo != 1) {
var tempSlide = currentSlide;
currentSlide = currentSlide.previousElementSibling;
tempSlide.classList.remove("show");
currentSlide.classList.add("show");
init();
}
}
// moves to right slide
function moveToRightSlide() {
if (currentSlideNo != totalSides) {
var tempSlide = currentSlide;
currentSlide = currentSlide.nextElementSibling;
tempSlide.classList.remove("show");
currentSlide.classList.add("show");
init();
}
}
// get current slide
function getCurrentSlideNo() {
let counter = 0;
slides.forEach((slide, i) => {
counter++;
if (slide.classList.contains("show")) {
currentSlideNo = counter;
}
});
}
// go full screen
function fullScreenMode() {
presentationController.classList.add("full-screen");
}
// update counter
function setSlideNo() {
slideNumber.innerText = `${currentSlideNo} of ${totalSides}`;
}