-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
133 lines (107 loc) · 3.05 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const inViewport = (entries) => {
entries.forEach(entry => {
if (entry.target.classList.contains('card')) {
entry.target.classList.toggle("card-animation", entry.isIntersecting);
}
});
};
const observer = new IntersectionObserver(inViewport);
// Attach observer to every [data-inviewport] element:
const cardsInViewport = document.querySelectorAll('.card');
cardsInViewport.forEach(cards => {
observer.observe(cards);
});
// PAGINATION SCRIPT
// get elements
const dropdownContainer = document.querySelector('.dropdown-menu')
const nextBtn = document.getElementById("next-button");
const prevBtn = document.getElementById("prev-button");
const listOfSkills = document.getElementById("paginate");
const pageNums = document.getElementById("pagination-numbers");
// stop propogation to not close on click
dropdownContainer.addEventListener("click", (e) => {
e.stopPropagation();
});
let currentPage = 1;
let skillsPerPage = 5;
const skillObj = [
{ skills: "HTML" },
{ skills: "CSS" },
{ skills: "JavaScript" },
{ skills: "Git" },
{ skills: "Accessibility" },
{ skills: "SEO" },
{ skills: "JIRA" },
{ skills: "Bootstrap" },
{ skills: "React" },
{ skills: "jQuery" },
{ skills: "Node.js" },
{ skills: "MongoDB" },
{ skills: "SQL Server" },
{ skills: "Debugging" },
{ skills: "CMS" }
];
let numPages = Math.ceil(skillObj.length / skillsPerPage);
nextBtn.addEventListener("click", nextPage);
prevBtn.addEventListener("click", prevPage);
function changePage(page)
{
// Validate page
if (page < 1) {
page = 1;
}
if (page > numPages) {
page = numPages;
}
listOfSkills.innerHTML = "";
for (let i = (page-1) * skillsPerPage; i < (page * skillsPerPage) && i < skillObj.length; i++) {
listOfSkills.innerHTML += `<li>${skillObj[i].skills}</li>`;
}
pageNums.innerHTML = page + "/" + numPages;
// Button Handler Function
btnVisibilityHandler(page);
}
// Functions
function btnVisibilityHandler(pages) {
if (pages == 1) {
prevBtn.classList.add('invisible');
prevBtn.classList.remove('visible');
}
else {
prevBtn.classList.remove('invisible');
prevBtn.classList.add('visible');
}
if (pages == numPages) {
nextBtn.classList.add('invisible');
nextBtn.classList.remove('visible');
}
else {
nextBtn.classList.remove('invisible');
nextBtn.classList.add('visible');
}
}
function prevPage()
{
if (currentPage > 1) {
currentPage--;
changePage(currentPage);
}
}
function nextPage()
{
if (currentPage < numPages) {
currentPage++;
changePage(currentPage);
}
}
window.onload = () => {
changePage(1);
};
// Close dropdown on mouseout
const dropdownArea = document.querySelector('.navbar');
const dropdownButton = document.getElementById('skills');
dropdownArea.addEventListener('mouseleave', () => {
if (dropdownButton.classList.contains("show")) {
dropdownButton.click();
}
});