-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.28 KB
/
index.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
// Initialize
const btn = document.querySelector(".navbar-toggler");
const menu = document.querySelector(".search-menu");
const crossBtn = document.querySelector(".cross");
const buttons = document.querySelector(".nav-link");
const API_KEY = "wJk7lutnfSTxbkNPYG5fJIeEYbWx9v76L65GSWyg";
const API_ENDPOINT = "https://api.nasa.gov/planetary/apod";
// NAVBAR
btn.addEventListener("click", () => {
menu.style.transform = "translateY(0%)";
menu.classList.remove("hidden");
menu.style.transition = "0.5s";
});
crossBtn.addEventListener("click", () => {
menu.style.transform = "translateY(-100%)";
});
buttons.addEventListener("click", () => {
menu.classList.add("hidden");
});
// API NASA
async function getNasaImage() {
try {
const response = await fetch(`${API_ENDPOINT}?api_key=${API_KEY}`);
const data = await response.json();
const imageUrl = data.url;
const nameUrl = data.copyright;
const titleUrl = data.title;
const titleElement = document.querySelector(".text-url");
const nameElement = document.querySelector(".name-url");
const imgElement = document.querySelector(".space");
imgElement.src = imageUrl;
nameElement.innerHTML = nameUrl;
titleElement.innerHTML = titleUrl;
} catch (error) {
console.error(error);
}
}
getNasaImage();