-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathblogScript.js
100 lines (97 loc) · 2.56 KB
/
blogScript.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
//Select the buttons
const prev = document.querySelector('.prev');
const next = document.querySelector('.next');
console.log(prev)
let count = 0;
let tracker = 0;
function moveCardsLeft() {
count = count - 402;
tracker++;
if (tracker === 0) {
prev.setAttribute('disabled', '');
} else {
prev.removeAttribute('disabled');
}
if (tracker === 8) {
next.setAttribute('disabled', '');
} else {
next.removeAttribute('disabled');
}
const cards = document.querySelectorAll('.blog-card');
cards.forEach(function (el, i, arr) {
el.style.transform = `translateX(${count}px)`;
});
}
function moveCardsRight() {
count = count + 402;
tracker --;
if (tracker === 0) {
prev.setAttribute('disabled', '');
} else {
prev.removeAttribute('disabled');
}
if (tracker === 8) {
next.removeAttribute('disabled', '');
} else {
next.removeAttribute('disabled');
}
const cards = document.querySelectorAll('.blog-card');
cards.forEach(function (el, i, arr) {
el.style.transform = `translateX(${count}px)`;
});
}
prev.addEventListener('click', () => {
moveCardsRight();
});
next.addEventListener('click', () => {
moveCardsLeft();
});
const mediaQuery = window.matchMedia('(max-width: 1000px)')
if (mediaQuery.matches){
const prev = document.querySelector('.blog-prev');
const next = document.querySelector('.blog-next');
let count = 0;
let tracker = 0;
function moveCardsLeft() {
count = count - 229;
tracker++;
if (tracker ===0) {
prev.setAttribute('disabled', '');
} else {
prev.removeAttribute('disabled');
}
if (tracker === 15) {
next.setAttribute('disabled', '');
} else {
next.removeAttribute('disabled');
}
const cards = document.querySelectorAll('.blog-card');
cards.forEach(function (el, i, arr) {
el.style.transform = `translateX(${count}px)`;
});
}
function moveCardsRight() {
count = count + 229;
tracker --;
if (tracker === 0) {
prev.setAttribute('disabled', '');
} else {
prev.removeAttribute('disabled');
}
if (tracker === 15) {
next.removeAttribute('disabled', '');
} else {
next.removeAttribute('disabled');
}
const cards = document.querySelectorAll('.blog-card');
cards.forEach(function (el, i, arr) {
el.style.transform = `translateX(${count}px)`;
});
}
prev.addEventListener('click', () => {
moveCardsRight();
});
next.addEventListener('click', () => {
moveCardsLeft();
});
}