-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
659 lines (627 loc) · 15.6 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&family=Bilbo+Swash+Caps&family=Concert+One&family=Creepster&family=East+Sea+Dokdo&family=IBM+Plex+Sans:wght@300&family=Lato&family=Love+Light&family=Love+Ya+Like+A+Sister&family=Loved+by+the+King&family=Lovers+Quarrel&family=Montserrat&family=Newsreader&family=Pacifico&family=Playfair+Display&family=Playfair+Display+SC&family=Poppins&family=Rampart+One&family=Roboto&family=Roboto+Flex:wght@800&display=swap" rel="stylesheet">
<!-------------------------boxicons cdn link------------------------>
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.css"/>
<title>Weather Web Application</title>
<style>
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
letter-spacing: 0.4px;
font-family: 'Lato', sans-serif;
}
:root
{
--main-background:#D7C0FF;
}
html
{
overflow-x: hidden;
scroll-behavior: smooth;
}
body
{
background: var(--main-background);
background: linear-gradient(rgba(0,0,0,0.0),rgba(0,0,0,0.0)),url('https://img.freepik.com/free-vector/aesthetic-purple-sky-background-vector-glitter-clouds-design_53876-157556.jpg?size=626&ext=jpg&ga=GA1.2.969831894.1654975018&semt=ais');
background-size: cover;
object-fit: cover;
background-repeat: no-repeat;
height: 100vh;
overflow-x: hidden;
}
.container
{
width: 100%;
height: 100%;
}
.frontpage
{
display: flex;
align-items: center;
flex-direction: column;
height: 100vh;
background:linear-gradient(rgba(150,0,0,0.1),rgba(150,0,0,0.1)),url('./nature.jpg');
background-size: cover;
object-fit: cover;
background-repeat: no-repeat;
width: 100%;
margin: auto;
transition: 0.8s ease;
}
.frontpage.active
{
transform:translateX(-100%);
}
.weather-front-image
{
max-width: 150px;
object-fit: cover;
}
.frontpage-contents
{
margin: 120px 15px 15px 15px ;
border-radius: 15px;
backdrop-filter: blur(10px);
width: 80%;
text-align: center;
padding:50px 10px;
position: relative;
z-index: 1;
color: white;
}
.frontpage-contents::before
{
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
backdrop-filter: blur(15px);
border-radius: 15px;
z-index: -1;
border:1px solid rgba(255,255,255,0.3);
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.4), -3px -3px 5px rgba(255, 255, 255, 0.2);
}
.frontpage-contents h2
{
width: 200px;
font-size: 25px;
margin: 20px auto;
}
.getting-started-btn
{
font-size: 15px;
padding: 10px 30px;
border-radius: 35px;
font-weight: bold;
color: black;
border: none;
margin-bottom: 20px;
position: relative;
z-index: 1;
overflow: hidden;
transition: 0.3s ease;
cursor: pointer;
}
.getting-started-btn:hover
{
background: black;
color: white;
}
.getting-started-btn::before
{
position: absolute;
content: "";
top:0;
left: 0;
width: 100%;
height: 400%;
z-index: -1;
background: linear-gradient(130deg,greenyellow,pink,cyan);
border-radius: 100px;
animation: btnanim 3s linear infinite;
}
@keyframes btnanim
{
0%
{
transform: rotate(0);
}
100%
{
transform: rotate(360deg);
}
}
.weatherInput
{
padding: 10px;
display: flex;
align-items: center;
justify-content:center;
flex-direction: column;
line-height: 1.5;
text-align: center;
}
.weatherInputField
{
display: flex;
align-items: center;
justify-content: center;
margin: 20px auto 10px auto;
padding: 7px 12px 7px 10px;
border:none;
background: white;
width: 90%;
border-radius: 5px;
column-gap: 4px;
}
.weatherInputField input
{
font-size: 15px;
width: 100%;
outline: none;
background: none;
border:none;
}
.searchBtn
{
font-size: 14px;
padding: 10px 15px;
background:white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
border-radius: 5px;
border:none;
font-weight: bold;
letter-spacing: 0.6px;
overflow: hidden;
position: relative;
z-index: 1;
width:120px;
transition: 0.2s ease;
}
.searchBtn:hover
{
background: black;
}
.searchBtn::before
{
position: absolute;
content: "";
top:10px;
left: 0;
width: 100%;
height: 200%;
z-index: -1;
background: linear-gradient(130deg,greenyellow,pink,cyan);
border-radius: 100px;
animation: btnanim2 3s linear infinite;
}
@keyframes btnanim2
{
0%
{
transform: rotate(0);
}
100%
{
transform: rotate(-360deg);
}
}
.location-content
{
display: flex;
align-items: center;
justify-content: center;
column-gap: 4px;
margin: 10px auto;
color:darkviolet;
}
.weather-Degree
{
position: relative;
}
.weather-Degree h1
{
font-size: 80px;
-webkit-text-stroke:2px;
-webkit-text-color:white;
letter-spacing: 0.8px;
color: darkviolet;
}
.weather-Degree-img
{
max-width: 150px;
object-fit: cover;
position: absolute;
bottom:0;
right: -70px;
animation: imganim 2s linear infinite;
}
@keyframes imganim
{
0%
{
bottom:0;
}
50%
{
bottom:20px;
}
100%
{
bottom:0;
}
}
.weather-Degree h2
{
margin-bottom: 5px;
color: white;
letter-spacing: 0.8px;
text-transform: capitalize;
}
.weather-pallete
{
width: 95%;
background: white;
padding: 15px 10px;
border-radius: 5px;
margin: 20px auto;
display: flex;
align-items: center;
justify-content: space-around;
}
.pallete-data
{
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
text-align: center;
}
.pallete-data i
{
margin-bottom: 5px;
background: darkviolet;
border-radius: 50%;
width: 30px;
height: 30px;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
.pallete-data small
{
font-weight: bold;
letter-spacing: 0.7px;
}
.pallete-data span
{
font-size: 14px;
}
.weather-forecasts
{
width: 90%;
margin: auto;
/* background: red;*/
}
.weather-forecasts h3
{
padding:0px 10px;
}
.weather-ul .weather-data
{
display: flex;
align-items: center;
justify-content: center;
flex-flow: column;
background:rgba(255,255,255,0.4);
box-shadow: 5px 5px 2px rgba(0, 0, 0, 0.1);
border:1px solid white;
border-radius: 35px;
width: 20%;
margin: 30px auto 20px auto;
padding: 10px;
position: relative;
z-index: 1;
text-align: center;
}
.forecast-img
{
width: 80px;
object-fit: cover;
}
.icon-overlay
{
width: 30px;
height: 30px;
background: rgba(0,0,0,0.12);
box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
position: absolute;
top:57%;
left: 50%;
border-radius: 50%;
transform: translate(-50%,-50%);
z-index: -1;
}
.weather-data span
{
font-weight: bold;
font-size: 13px;
margin-top: 2px;
background: white;
padding: 10px;
border-radius: 35px;
}
.weather-data small
{
font-weight: bold;
font-size: 15px;
margin-bottom: 5px;
}
.swiper
{
width: 85%;
margin: auto;
padding:0 5px 0 5px;
}
.weather-container
{
transform: translateY(0);
transition: 0.8s ease;
width: 100%;
height: 100%;
display: none;
animation: divanim 1.5s ease-in-out;
opacity: 0;
}
@keyframes divanim
{
0%
{
transform: translateY(0);
}
100%
{
transform: translateY(-100%);
}
}
.weather-container.active
{
transform: translateY(-100%);
display: block;
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<div class="frontpage">
<div class="frontpage-contents">
<img src="https://cdn-icons-png.flaticon.com/512/1779/1779882.png" alt="weather-front-image" class="weather-front-image">
<h2>Weather <span style="font-size: 30px;font-weight: 100;">Forecasts</span></h2>
<button type="button" name="" class="getting-started-btn">Get Start</button>
<p>Check any weather</p>
</div>
</div>
<!---weather input code starts--->
<div class="weather-container">
<div class="weatherInputField">
<i class='bx bx-search-alt'></i>
<input class="citySearch" type="text" name="" placeholder="Search City...">
<button type="button" name="" class="searchBtn">Search</button>
</div>
<div class="weatherInput">
<div class="location-data">
<div class="location-content">
<i class='bx bxs-map'></i>
<h3>-----</h3>
</div>
<p>Date Month Year</p>
</div>
<div class="weather-Degree">
<h1>--°</h1>
<!-------<img src="https://openweathermap.org/img/wn/[email protected]" alt="weather-Degree-image" class="weather-Degree-img">----->
<h2>-----</h2>
</div>
<div class="weather-pallete">
<div class="pallete-data">
<i class='bx bx-water'></i>
<small>-- M/B</small>
<span>Pressure</span>
</div>
<div class="pallete-data">
<i class='bx bxs-droplet-half' ></i>
<small>-- %</small>
<span>Humidity</span>
</div>
<div class="pallete-data">
<i class='bx bx-wind' ></i>
<small>-- M/S</small>
<span>wind Speed</span>
</div>
</div>
</div>
<!-- weather input code ends -->
<!-- weather forecasts code starts -->
<div class="swiper mySwiper weather-forecasts">
<h3>5 Days Weather Forecast (Slide)</h3>
<ul class="swiper-wrapper weather-ul">
<li class="swiper-slide weather-data">
<span>-- -- --</span>
<!-- <img src="http://openweathermap.org/img/wn/[email protected]" alt="forecast-image" class="forecast-img"> -->
<!-- <div class="icon-overlay"></div> -->
<small>--°</small>
</li>
<li class="swiper-slide weather-data">
<span>-- -- --</span>
<!-- <img src="http://openweathermap.org/img/wn/[email protected]" alt="forecast-image" class="forecast-img"> -->
<!-- <div class="icon-overlay"></div> -->
<small>--°</small>
</li>
<li class="swiper-slide weather-data">
<span>-- -- --</span>
<!-- <img src="http://openweathermap.org/img/wn/[email protected]" alt="forecast-image" class="forecast-img"> -->
<!-- <div class="icon-overlay"></div> -->
<small>--°</small>
</li>
<li class="swiper-slide weather-data">
<span>-- -- --</span>
<!-- <img src="http://openweathermap.org/img/wn/[email protected]" alt="forecast-image" class="forecast-img"> -->
<!-- <div class="icon-overlay"></div> -->
<small>--°</small>
</li>
<li class="swiper-slide weather-data">
<span>-- -- --</span>
<!-- <img src="http://openweathermap.org/img/wn/[email protected]" alt="forecast-image" class="forecast-img"> -->
<!-- <div class="icon-overlay"></div> -->
<small>--°</small>
</li>
</ul>
</div>
</div>
</div>
<!-- weather forecasts code ends -->
<script src="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.js"></script>
<!-- Initialize Swiper -->
<script defer>
var swiper = new Swiper(".mySwiper", {
slidesPerView: 3,
spaceBetween: 15,
freeMode: true,
});
//working on weather updates
const searchBtn = document.querySelector('.searchBtn');
const cityNameInput = document.querySelector('.citySearch');
const apiKey = 'b8e6343adb114d2c88af0939f6b1a6c4';
const weeks = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
const WeatherDegree = document.querySelector('.weatherInput');
const locationData = document.querySelector('.location-data');
const weatherPallete = document.querySelector('.weather-pallete');
const weatherUL = document.querySelector('.weather-ul');
const gettingStartedBtn = document.querySelector('.getting-started-btn');
gettingStartedBtn.addEventListener('click',function(){
document.querySelector('.frontpage').classList.add('active');
document.querySelector('.weather-container').classList.add('active');
})
// creating a function named createWeatherCard
function createWeatherCard(cityName2, weatherItem2, index2)
{
if(index2 === 0)
{
return `
<div class="location-data">
<div class="location-content">
<i class='bx bxs-map'></i>
<h3>${cityName2}</h3>
</div>
<p>${weatherItem2.dt_txt.split(' ')[0]}</p>
</div>
<div class="weather-Degree">
<h1>${(weatherItem2.main.temp - 273.15).toFixed(2)}°</h1>
<img src="https://openweathermap.org/img/wn/${weatherItem2.weather[0].icon}@4x.png" alt="weather-Degree-image" class="weather-Degree-img">
<h2>${weatherItem2.weather[0].description}</h2>
</div>
<div class="weather-pallete">
<div class="pallete-data">
<i class='bx bx-water'></i>
<small>${weatherItem2.main.pressure} M/B</small>
<span>Pressure</span>
</div>
<div class="pallete-data">
<i class='bx bxs-droplet-half' ></i>
<small>${weatherItem2.main.humidity}%</small>
<span>Humidity</span>
</div>
<div class="pallete-data">
<i class='bx bx-wind' ></i>
<small>${weatherItem2.wind.speed} M/S</small>
<span>wind Speed</span>
</div>
</div>
`
}
else
{
return `
<li class="swiper-slide weather-data">
<span>${weatherItem2.dt_txt.split(' ')[0]}</span>
<img src="http://openweathermap.org/img/wn/${weatherItem2.weather[0].icon}@2x.png" alt="forecast-image" class="forecast-img">
<div class="icon-overlay"></div>
<small>${(weatherItem2.main.temp - 273.15).toFixed(2)}°</small>
</li>
`
}
}
//creating a function named gettingWeatherDetails
function gettingWeatherDetails(cityWeather, lat, lon)
{
const weather_api_url = `http://api.openweathermap.org/data/2.5/forecast?lat=${lat}&lon=${lon}&appid=${apiKey}`;
fetch(weather_api_url).then(res=>res.json()).then(data=>{
const forecastDays = [];
const fiveDaysForecast = data.list.filter(function(forecast){
const forecastdate = new Date(forecast.dt_txt).getDate();
if(!forecastDays.includes(forecastdate))
{
return forecastDays.push(forecastdate);
}
});
console.log(data);
//when weather is fetched the HTML elements is removed and new will be added
cityNameInput.value = "";
WeatherDegree.innerHTML = "";
locationData.innerHTML ="";
weatherPallete.innerHTML ="";
weatherUL.innerHTML = "";
fiveDaysForecast.forEach(function(weatherItem,index){
if(index === 0)
{
WeatherDegree.insertAdjacentHTML('beforeend',createWeatherCard(cityWeather, weatherItem, index));
}
else
{
weatherUL.insertAdjacentHTML('beforeend',createWeatherCard(cityWeather, weatherItem, index));
}
});
}).catch(() =>{
alert('Error Occured While Fetching the Coordinates of Weather');
});
}
//working on search Button
searchBtn.addEventListener('click',function(){
const cityName = cityNameInput.value.trim();//trim to remove extra spaces
if(cityName == "")
{
alert("Please Enter the City Name");
return;
}
else
{
const geocoding_api_url = `http://api.openweathermap.org/geo/1.0/direct?q=${cityName}&limit=1&appid=${apiKey}`;
fetch(geocoding_api_url).then(res =>res.json()).then(data=>{
if(!data.length) //if you enter wrong keyword or city name
{
return alert(`${cityName} isn't a valid city Name`);
}
else
{
const { name,lat,lon } = data[0]; //storing the value of Name,latitute and value of longitude in data array
gettingWeatherDetails(name, lat, lon);//Now We have to create a function named gettingWeatherDetails
}
// console.log(data);
}).catch(()=>{
alert("Error Occured While Fetching the Coordinates");
})
}
})
</script>
</body>
</html>