WEBLEB
होम
संपादक
लॉग इन करें
Pro
हिंदी
English
Français
Español
Português
Deutsch
Italiano
हिंदी
मौसम ऐप
2516
Andev.web
संपादक में खोलें
अपना कोड प्रकाशित करें
क्या आपको एक वेबसाइट चाहिए?
अनुशंसित
29 November 2024
कुशल ऐप58 द्वारा एक कोड
22 May 2025
भाषण ऐप
13 June 2025
अलार्म घड़ी और स्टॉपवॉच ऐप उपयोगकर्ता इंटरफ़ेस
HTML
Copy
Andev Web
Lo1ndon
31
o
overcast clouds
clouds
98
%
humidity
98
%
pressure
1011
hPa
CSS
Copy
body{ margin: 0; min-height: 100vh; display: flex; justify-content: center; align-items: center; background-image: linear-gradient( to bottom, #dcdcdc 50%, #e9e9e9 50% ); font-family: sans-serif; } *{ padding: 0; margin: 0; } main{ width: 300px; height: max-content; min-height: 300px; background-color: #f7f7f7; border-radius: 30px; box-shadow: 0 30px 50px #5553; padding: 30px; box-sizing: border-box; } main form{ border: 1px solid #5552; display: flex; border-radius: 30px; justify-content: space-between; } main form input, main form button{ border: none; background-color: transparent; outline: none; padding: 10px; box-sizing: border-box; } main form i{ opacity: 0.7; } main .result{ padding-top: 20px; text-align: center; } main .result .name{ font-weight: bold; font-size: large; display: flex; justify-content: center; align-items: center; gap: 10px; } main .temperature img{ width: 150px; filter: drop-shadow(0 10px 50px #555); } main .temperature figcaption{ font-size: 3em; } main .description{ padding: 10px 0 30px; } main ul{ list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; } main li{ background-color: #f78a55; color: #fff; border-radius: 10px; padding: 20px 10px; background-image: linear-gradient( to bottom, transparent 50%, #0003 50% ); font-weight: bold; font-size: small; } main ul li i{ font-size: 2em; margin: 20px 0; display: block!important; } main li:nth-child(2){ background-color: #b56291; } main li:nth-child(3){ background-color: #48567b; } main.error{ animation: errorEffect 0.3s linear 1; } @keyframes errorEffect{ 0%{ transform: translate(10px, 5px) } 25%{ transform: translate(-5px, 0) } 50%{ transform: translate(8px, 2px) } 75%{ transform: translate(-2px, 5px) } 100%{ transform: translate(0, 0); } }
JS
Copy
let id = '9505fd1df737e20152fbd78cdb289b6a'; let url = 'https://api.openweathermap.org/data/2.5/weather?units=metric&appid=' + id; let city = document.querySelector('.name'); let form = document.querySelector("form"); let temperature = document.querySelector('.temperature'); let description = document.querySelector('.description'); let valueSearch = document.getElementById('name'); let clouds = document.getElementById('clouds'); let humidity = document.getElementById('humidity'); let pressure = document.getElementById('pressure'); let main = document.querySelector('main'); form.addEventListener("submit", (e) => { e.preventDefault(); if(valueSearch.value != ''){ searchWeather(); } }); const searchWeather = () => { fetch(url+'&q='+ valueSearch.value) .then(response => response.json()) .then(data => { console.log(data); if(data.cod == 200){ city.querySelector('figcaption').innerHTML = data.name; city.querySelector('img').src = `https://flagsapi.com/${data.sys.country}/shiny/32.png`; temperature.querySelector('img').src = `https://openweathermap.org/img/wn/${data.weather[0].icon}@4x.png`; temperature.querySelector('span').innerText = data.main.temp; description.innerText = data.weather[0].description; clouds.innerText = data.clouds.all; humidity.innerText = data.main.humidity; pressure.innerText = data.main.pressure; }else{ main.classList.add('error'); setTimeout(() => { main.classList.remove('error'); }, 1000); } valueSearch.value = ''; }) } // search Default const initApp = () => { valueSearch.value = 'Washington'; searchWeather(); } initApp();