-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
31 lines (27 loc) · 1.06 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
const categoryTitle = document.querySelectorAll('.category-title');
const allCategoryPosts = document.querySelectorAll('.all');
for(let i = 0; i < categoryTitle.length; i++){
categoryTitle[i].addEventListener('click', filterPosts.bind(this, categoryTitle[i]));
}
function filterPosts(item){
changeActivePosition(item);
for(let i = 0; i < allCategoryPosts.length; i++){
if(allCategoryPosts[i].classList.contains(item.attributes.id.value)){
allCategoryPosts[i].style.display = "block";
} else {
allCategoryPosts[i].style.display = "none";
}
}
}
function changeActivePosition(activeItem){
for(let i = 0; i < categoryTitle.length; i++){
categoryTitle[i].classList.remove('active');
}
activeItem.classList.add('active');
};
window.addEventListener('scroll', function () {
var header = document.querySelector('nav');
var height = window.innerHeight;
var width = window.innerWidth;
header.classList.toggle('sticky', window.scrollY > 0.20 * height);
});