WEBLEB
Inicio
Editora de código
Chat
Reto
Iniciar sesión
Pro
Español
English
Français
Español
Página web sobre clima limpio
256
0
Tarjetas
angrybird76
Seguir
0
Remix
Abrir en el editor
Pantalla completa
Comentar
Publica tu código
0
Recomendado
18 November 2024
Plantilla de sitio web de portafolio moderno
23 August 2024
Página de inicio de React Netflix
27 May 2025
Página de contacto futurista
HTML
Copy
Weather Web
o
clouds
%
humidity
%
pressure
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; transition: opacity 0.3s ease; } /* Hidden state to stop the flash of unstyled content */ main .result.hidden { opacity: 0; visibility: hidden; } 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 #e0f714); } 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 resultSection = document.querySelector('.result'); 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(valueSearch.value); valueSearch.value = ''; } }); const searchWeather = (cityName) => { fetch(url + '&q=' + cityName) .then(response => response.json()) .then(data => { console.log(data); if(data.cod == 200){ // Populating the clean HTML structure city.querySelector('figcaption').innerHTML = data.name; city.querySelector('img').src = `https://flagsapi.com/${data.sys.country}/shiny/32.png`; city.querySelector('img').alt = data.sys.country; temperature.querySelector('img').src = `https://openweathermap.org/img/wn/${data.weather[0].icon}@4x.png`; temperature.querySelector('span').innerText = Math.round(data.main.temp); description.innerText = data.weather[0].description; clouds.innerText = data.clouds.all; humidity.innerText = data.main.humidity; pressure.innerText = data.main.pressure; // Reveal the content smoothly now that data is safe to look at resultSection.classList.remove('hidden'); } else { main.classList.add('error'); setTimeout(() => { main.classList.remove('error'); }, 1000); } }) .catch(err => console.error("Error fetching data:", err)); } // search Default const initApp = () => { searchWeather('Multan,PK'); } initApp();
Comentarios
0
Inicia sesión para unirte a la conversación
…