-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
76 lines (61 loc) · 1.84 KB
/
scripts.js
File metadata and controls
76 lines (61 loc) · 1.84 KB
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
fetch('https://fakestoreapi.com/products?limit=9')
.then(res=>res.json())
.then(json=>addToPage(json));
function addToPage(content){
console.log(content);
const container = document.getElementById("container");
let colCounter = 1;
let rowCounter = 1;
let actualRow;
content.forEach(element => {
if((colCounter-1) % 3 == 0){
rowCounter++;
actualRow = newRow(rowCounter);
}
newCol(element, actualRow, colCounter);
colCounter++;
});
}
function newCol(element, destination, id){
let col = document.createElement('div');
col.classList.add('col-md-4');
col.classList.add('p-5');
col.setAttribute('id', 'product-' + id);
col.setAttribute('style', 'height: 500px')
let img = document.createElement('img');;
img.src = element.image;
img.classList.add('list-image');
let imgContainer = document.createElement('div');
imgContainer.classList.add('imgContainer');
imgContainer.appendChild(img);
let a = document.createElement('p');
let textNode = document.createTextNode(element.title);
a.appendChild(textNode);
col.appendChild(imgContainer);
col.appendChild(a);
destination.appendChild(col);
}
function newRow(id){
let row = document.createElement('div');
row.classList.add('row');
row.setAttribute('id', 'row-' + id)
const container = document.getElementById('container');
container.appendChild(row);
return row;
}
let images = [];
let i = 0;
let time = 3000;
images[0] = 'img/1.jpg';
images[1] = 'img/2.jpg';
images[2] = 'img/3.jpg';
images[3] = 'img/4.jpg';
function changeImg(){
document.slide.src = images[i];
i++;
if(images.length === i){
i = 0;
}
setTimeout("changeImg()", time);
}
window.onload = changeImg;