Local Weather
How do I make an local weather?
This application will detect your location and show the weather. You can also search for other locations. DOESNT WORK WITH HTTPS.. What is a local weather? How do you make a local weather? This script and codes were developed by Mihkel on 08 December 2022, Thursday.
Local Weather - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Local Weather</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html>
<head> <meta charset="UTF-8"> <title>Local Weather</title> <link href='https://fonts.googleapis.com/css?family=Oswald:400,700,300' rel='stylesheet' type='text/css'>
</head>
<body> <div class="container text-center"> <input id="search-bar" class="form-control" type="text" placeholder="Search city.."> <button class="btn" id="temp-switch" type="button">°F</button> <div class="temp-container"> <h1 id="temperature"></h1> <img id ="icon" src=""> </div> <div class="info-box"> <div class="info-col"> <img class="info-icon" src="https://www.upload.ee/image/6018139/location-icon.png"> <p>location</p> <h3 id="location">.</h3> </div> <div class="info-col"> <img class="info-icon" src="https://www.upload.ee/image/6018141/cloud-icon.png"> <p>cloudiness</p> <h3 id="clouds">.</h3> </div> <div class="info-col"> <img class="info-icon" src="https://www.upload.ee/image/6018142/humidity-icon.png"> <p>humidity</p> <h3 id="humidity">.</h3> </div> <div class="info-col"> <img class="info-icon" src="https://www.upload.ee/image/6018143/wind-icon.png"> <p>wind</p> <h3 id="wind">.</h3> </div> </div> </div>
</body>
</html> <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Local Weather - Script Codes CSS Codes
body { background-image:url("https://www.upload.ee/image/6018137/background-min.jpg"); min-height:100vh; background-repeat: no-repeat; background-size:100% 100%; color:#000; font-family: 'Oswald', sans-serif;
}
#search-bar[type="text"]{ background-color: rgba(255, 255, 255, 0.2); width:325px; margin:0 auto; color:#000; margin-top:10%;;
}
#search-bar:focus { border-color:#D2B48C; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(210, 180, 140, 1);
}
#temp-switch { width:30px; height:35px; background-color: rgba(255, 255, 255, 0.2); font-weight: bold; transition: 0.3s; margin-top:4%; padding-left:5px;
}
#temp-switch:hover { background-color: #D2B48C;
}
#temp-switch:focus {outline:none;}
#temperature { display:inline-block; font-size:3em; margin-top:40px;
}
#icon { display:inline-block; margin-left:5px;
}
.info-box { margin-top:30px;
}
.info-col { width:250px; height:154px; background-color: rgba(255, 255, 255, 0.2); text-align:center; display:inline-block; white-space:nowrap; overflow:hidden; margin:0 10px;
}
.info-icon { width:75px; height:75px;
}
Local Weather - Script Codes JS Codes
// DOES NOT WORK WITH HTTPS
// USE HTTP
// https://codepen.io/Krokodill/full/YWjZor/
window.onload = getWeather;
// get coordinates
function getWeather() { $.getJSON("http://ipinfo.io", function(response) { var coords = response.loc.split(","); var weatherUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + coords[0] + "&lon=" + coords[1] + "&appid=dbb624c32c7f0d652500552c5ebbde56"; // weather api $.getJSON(weatherUrl, function(api) { if ($("#temp-switch").text() === "°F"){ var celsius = (api.main.temp - 273.15).toFixed(1); $("#temperature").html(celsius + "°C"); } else if ($("#temp-switch").text() === "°C") { var celsius = (api.main.temp - 273.15).toFixed(1); fahrenheit = (celsius * (9 / 5) + 32).toFixed(2); $("#temperature").html(fahrenheit + "°F") } var iconId = api.weather[0].icon var iconUrl = "http://openweathermap.org/img/w/" + iconId + ".png"; $("#icon").attr("src", iconUrl); $("#location").html(api.name); $("#clouds").html(api.weather[0].description + ", " + api.clouds.all + "%"); $("#humidity").html(api.main.humidity + "%"); $("#wind").html(api.wind.speed + " m/s, " + api.wind.deg.toFixed() + "°"); }) })
}
function searchCity(e) { var search = $(this).val(); if (e.keyCode === 13) { $.getJSON("http://api.openweathermap.org/data/2.5/weather?q="+search+"&appid=dbb624c32c7f0d652500552c5ebbde56", function(data) { if ($("#temp-switch").text() === "°F"){ var celsius = (data.main.temp - 273.15).toFixed(1); $("#temperature").html(celsius + "°C"); } else if ($("#temp-switch").text() === "°C") { var celsius = (data.main.temp - 273.15).toFixed(1); fahrenheit = (celsius * (9 / 5) + 32).toFixed(2); $("#temperature").html(fahrenheit + "°F") } var iconId = data.weather[0].icon var iconUrl = "http://openweathermap.org/img/w/" + iconId + ".png"; $("#icon").attr("src", iconUrl); $("#location").html(data.name); $("#clouds").html(data.weather[0].description + ", " + data.clouds.all + "%"); $("#humidity").html(data.main.humidity + "%"); $("#wind").html(data.wind.speed + " m/s, " + data.wind.deg.toFixed() + "°"); }) } else if (search.length === 0) { getWeather(); }
}
function toggleTemp() { if ($("#temp-switch").text() === "°F") { var fahrenheit = parseFloat($("#temperature").text()); fahrenheit = (fahrenheit * (9 / 5) + 32).toFixed(2); $("#temperature").html(fahrenheit +"°F"); $("#temp-switch").text("°C"); } else if ($("#temp-switch").text() === "°C") { var celsius = parseFloat($("#temperature").text()); celsius = ((celsius - 32) * (5 / 9)).toFixed(1); $("#temperature").html(celsius + "°C"); $("#temp-switch").text("°F"); }
}
$("#search-bar").keydown(searchCity)
$("#temp-switch").on("click", toggleTemp);
Developer | Mihkel |
Username | Krokodill |
Uploaded | December 08, 2022 |
Rating | 3 |
Size | 3,340 Kb |
Views | 6,072 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Dungeon Crawler | 5,057 Kb |
React Pokedex | 13,070 Kb |
Simon Game | 4,975 Kb |
Tic-Tac-Toe | 4,853 Kb |
Loading animation | 1,572 Kb |
React Recipe Box | 5,347 Kb |
Snake Game | 2,941 Kb |
Form validation with jQuery | 2,641 Kb |
Pomodoro Timer | 3,599 Kb |
Game of Life | 2,922 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Parallax-ish Sliding Content | Jdsteinbach | 2,748 Kb |
Word Wrap Algorithm for Multiline Canvas Text | Peterhry | 2,349 Kb |
Konami Code Easter Egg | Teolitto | 3,051 Kb |
Template | Indra_z85 | 2,323 Kb |
Sinclair Research Computers | MattCowley | 3,068 Kb |
Parallax with only CSS | Thulioph | 2,297 Kb |
Lunar eclipse | Ademilter | 2,056 Kb |
Blackberry Mock | Zacharyolson | 1,865 Kb |
How to add Css Fold Notes In Blogger By Askwithloud.com | Askwithloud | 2,280 Kb |
CSS Letter animations | Sladix | 2,116 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!