-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
89 lines (71 loc) · 2.3 KB
/
app.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
const grid = document.querySelector('.grid');
const gridItems = [...document.querySelectorAll('.grid-item')];
const gridRows = [...document.querySelectorAll('.row')];
const images = [...document.querySelectorAll('.img')];
const heading = document.querySelector('.heading');
const headingtwo = document.querySelector('.heading-two');
images.forEach((img, idx) => {
img.style.backgroundImage = `url(./images/${idx + 1}.jpg)`
});
gridItems.forEach((item, idx) => {
item.addEventListener('click', (e) => {
let isActive = e.target.classList.contains('active')
console.log(e.target)
for(let i = 0; i < gridItems.length; i++){
gridItems[i].classList.remove('active');
}
if(isActive){
gridRows[0].style.height = '50%';
gridRows[1].style.height = '50%';
for(let i = 0; i < gridItems.length; i++){
gridItems[i].classList.remove('expand');
}
return;
}
gridItems[idx].classList.add('active');
if(window.innerWidth > 600){
if(idx == 0 || idx == 3){
setActive([0, 3]);
}
if(idx == 1 || idx == 4){
setActive([1, 4]);
}
if(idx == 2 || idx == 5){
setActive([2, 5]);
}
if(idx <=2){
gridRows[0].style.height = '70%'
gridRows[1].style.height = '30%'
}else{
gridRows[0].style.height = '30%'
gridRows[1].style.height = '70%'
}
}
})
})
function setActive(idxArr){
for(let i = 0; i < gridItems.length; i++){
if(idxArr.includes(i)){
gridItems[i].classList.add('expand');
}else{
gridItems[i].classList.remove('expand');
}
}
};
window.addEventListener('resize', () => {
for(let i = 0; i < gridItems.length; i++){
gridItems[i].classList.remove('active');
gridItems[i].classList.remove('expand');
gridRows[0].style.height = '50%'
gridRows[1].style.height = '50%'
}
})
setTimeout(() => {
heading.classList.add('show');
}, 500);
setTimeout(() => {
headingtwo.classList.add('show');
}, 550);
setTimeout(() => {
grid.style.opacity = 1
}, 1000);