-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
28 lines (22 loc) · 1 KB
/
home.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
//how to connect the next and prev btn with the product container//
// select all product containers using query selector all method//
const stuffproducts = [...document.querySelectorAll('.stuff-product')];
const nxtbtn = [...document.querySelectorAll('.next-btn')];
const prev = [...document.querySelectorAll('.prev-btn')];
//now loop through each card using forEach method//
stuffproducts.forEach((items, i) => {
//store the stuff dimension thru items//
//store the stuff width to the stuff dimension//
let stuffDimension = items.getBoundingClientRect();
let stuffWidth = stuffDimension.width;
//now add click event to next button of the current index
//ncrease item scroll left value to stuff width
nxtbtn[i].addEventListener('click', () =>{
items.scrollLeft += stuffWidth;
})
//now do same thing with prev but decrement the item scroll left variable
//to the stuff width//
prev[i].addEventListener('click', () =>{
items.scrollLeft -= stuffWidth;
})
})