-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
116 lines (104 loc) · 3.85 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather App</title>
<style>body, html {
margin: 0;
padding: 0;
height: 100%;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
background: url('weather image.png') no-repeat center center/cover;
overflow: hidden;
}
.weather-container {
text-align: center;
color: white;
padding: 20px;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 10px;
box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
position: relative;
animation: flicker 1.5s infinite alternate;
}
@keyframes flicker {
0% { box-shadow: 0 0 20px rgba(255, 255, 255, 0.5); }
50% { box-shadow: 0 0 30px rgba(255, 255, 255, 0.7); }
100% { box-shadow: 0 0 20px rgba(255, 255, 255, 0.5); }
}
#locationInput {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
border: none;
}
button {
padding: 10px 20px;
margin-top: 10px;
border-radius: 5px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="weather-container">
<h1>Weather Information</h1>
<div id="weather">
<p>Location: <span id="location"></span></p>
<p>Temperature: <span id="temperature"></span>°C</p>
<p>Conditions: <span id="conditions"></span></p>
<input type="text" id="locationInput" placeholder="Enter location">
<button onclick="getWeatherByInput()">Get Weather</button>
</div>
</div>
<script>const apiKey = 'fcc8de7015bbb202209bbf0261babf4c';
const baseUrl = 'https://api.openweathermap.org/data/2.5/';
async function getWeatherByLocation(lat, lon) {
const url = `${baseUrl}weather?lat=${lat}&lon=${lon}&units=metric&appid=${apiKey}`;
try {
const response = await fetch(url);
const data = await response.json();
updateWeather(data);
} catch (error) {
console.error('Error fetching weather data:', error);
}
}
async function getWeatherByInput() {
const location = document.getElementById('locationInput').value;
const url = `${baseUrl}weather?q=${location}&units=metric&appid=${apiKey}`;
try {
const response = await fetch(url);
const data = await response.json();
updateWeather(data);
} catch (error) {
console.error('Error fetching weather data:', error);
}
}
function updateWeather(data) {
document.getElementById('location').innerText = data.name;
document.getElementById('temperature').innerText = data.main.temp;
document.getElementById('conditions').innerText = data.weather[0].description;
}
function getUserLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
getWeatherByLocation(position.coords.latitude, position.coords.longitude);
});
} else {
alert("Geolocation is not supported by this browser.");
}
}
document.addEventListener('DOMContentLoaded', getUserLocation);
</script>
</body>
</html>