-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
134 lines (121 loc) · 3.37 KB
/
main.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function toggleNavVisibility() {
const nav = document.querySelector('header nav');
const html = document.children[0];
const body = html.children[1];
const header = body.children[0];
//const nav = header.children[1];
nav.classList.toggle('visible');
// jQuery
}
const categories = [
{
id: 1,
name: 'Art',
background: './assets/categories/category1.png',
icon: './assets/icons/PaintBrush.svg',
},
{
id: 2,
name: 'Collectibles',
background: './assets/categories/category2.png',
icon: './assets/icons/Swatches.svg',
},
{
id: 3,
name: 'Music',
background: './assets/categories/category3.png',
icon: './assets/icons/MusicNotes.svg',
},
{
id: 4,
name: 'Photography',
background: './assets/categories/category4.png',
icon: './assets/icons/Camera.svg',
},
{
id: 5,
name: 'Video',
background: './assets/categories/category5.png',
icon: './assets/icons/VideoCamera.svg',
},
{
id: 6,
name: 'Utility',
background: './assets/categories/category6.png',
icon: './assets/icons/MagicWand.svg',
},
{
id: 7,
name: 'Sport',
background: './assets/categories/category7.png',
icon: './assets/icons/Basketball.svg',
},
{
id: 8,
name: 'Virtual Worlds',
background: './assets/categories/category8.png',
icon: './assets/icons/Planet.svg',
},
];
const categoriesContainer = document.querySelector('.categories-grid');
function renderCategories() {
for (const item of categories) {
const newCategory = document.createElement('div');
categoriesContainer.appendChild(newCategory);
newCategory.outerHTML = `
<div class="category-card">
<div class="top-part">
<img src="${item.background}" />
<div class="background"></div>
<img class="icon" src="${item.icon}" />
</div>
<div>${item.name}</div>
</div>`;
}
}
renderCategories();
const firstCard = document.querySelector('.category-card:first-child');
const marginValue = -270;
const leftCarouselBtn = document.querySelector('.carousel-btn.left');
const rightCarouselBtn = document.querySelector('.carousel-btn.right');
let currentSlide = 0;
const pageWidth = document.body.clientWidth;
function doLeftSlide() {
if (currentSlide > 0) {
currentSlide--;
firstCard.style.marginLeft = marginValue * currentSlide + 'px';
console.log('<-');
rightCarouselBtn.classList.remove('disabled');
if (currentSlide === 0) {
leftCarouselBtn.classList.add('disabled');
}
}
}
function doRightSlide() {
if (pageWidth > 850 && currentSlide < 5 || pageWidth <= 850 && currentSlide < 8) {
currentSlide++;
firstCard.style.marginLeft = marginValue * currentSlide + 'px';
console.log('->');
leftCarouselBtn.classList.remove('disabled');
if (pageWidth > 850 && currentSlide === 5 || pageWidth <= 850 && currentSlide === 8) {
rightCarouselBtn.classList.add('disabled');
}
}
}
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(data => console.log(data));
const payload = {
title: 'foo',
body: 'bar',
userId: 1,
};
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})
.then((response) => response.json())
.then((json) => console.log(json));