-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (62 loc) · 2.39 KB
/
Copy pathscript.js
File metadata and controls
85 lines (62 loc) · 2.39 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
77
78
79
80
81
82
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'e0dbbea06amshb39900452222291p13449djsne0c8b07d9a75',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const getWeather = (city) => {
document.getElementById("cityname").innerHTML = city;
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city, options)
.then(response => response.json())
.then((response) => {
console.log(response)
cloud_pct = response.cloud_pct
temp = response.temp
feels_like = response.feels_like
humidity = response.humidity
min_temp = response.min_temp
max_temp = response.max_temp
wind_speed = response.wind_speed
wind_degrees = response.wind_degrees
sunrise = response.sunrise
sunset = response.sunset
date_sunrise = new Date(sunrise * 1000).toLocaleTimeString();
date_sunset = new Date(sunset * 1000).toLocaleTimeString();
document.getElementById("temp").innerHTML = temp;
document.getElementById("temp_big").innerHTML = temp;
document.getElementById("feels_like").innerHTML = feels_like;
document.getElementById("humidity").innerHTML = humidity;
document.getElementById("humidity\_big").innerHTML = humidity;
document.getElementById("min_temp").innerHTML = min_temp;
document.getElementById("max_temp").innerHTML = max_temp;
document.getElementById("wind_speed").innerHTML = wind_speed;
document.getElementById("wind_speed_big").innerHTML = wind_speed;
document.getElementById("sunrise").innerHTML = date_sunrise;
document.getElementById("sunset").innerHTML = date_sunset;
})
.catch(err => console.log(err));
}
// Getting Button's ID and adding click event listener to get the Searchbar value (i.e. city)
document.getElementById("submit").addEventListener("click", (e) => {
// To prevent refreshing of page again and again
e.preventDefault()
// Searchbar id is city
City = document.getElementById("city").value;
// Passing the city to getWeather function above
getWeather(City);
})
const cursor = document.querySelector(".cursor")
// Follow cursor on mousemove
document.addEventListener("mousemove", (e) => {
let x = e.pageX;
let y = e.pageY;
cursor.style.top = y + "px";
cursor.style.left = x + "px";
cursor.style.display = "block";
// When we stop mouse, the animation display will stop
function mouseStopped(){
cursor.style.display = "none";
}
timeout = setTimeout(mouseStopped, 2000)
})