-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoManager.js
More file actions
39 lines (34 loc) · 1.05 KB
/
PhotoManager.js
File metadata and controls
39 lines (34 loc) · 1.05 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
/*
* This class has been deprecated now that unsplash has changed their API
* May update this in the future to change to a different API
* ... but if I did that then you wouldn't be reading this
*/
export default class PhotoManager {
constructor() {
this.photo = "";
}
async getPhotoFromUnsplash() {
const url = getPhotoURL();
const request = await fetch(url);
const data = await request.json();
this.photo = data;
return this.photo;
}
getPhotoURL() {
if (isMobileView()) {
return "https://source.unsplash.com/1242x2688/?nature,water";
} else {
return "https://source.unsplash.com/1920x1080/?nature,water";
}
}
isMobileView() {
return window.innerWidth < 800;
}
setBackground(element) {
const gradient = "linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), ";
element.style.background = gradient + `url('${this.photo.url}')`;
element.style.backgroundRepeat = "no-repeat";
element.style.backgroundPosition = "center center";
element.style.backgroundSize = "cover";
}
}