Weather
How do I make an weather?
What is a weather? How do you make a weather? This script and codes were developed by Adz on 04 November 2022, Friday.
Weather - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Weather</title> <link href='https://fonts.googleapis.com/css?family=Roboto:100,300,700,400' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width"> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div> <center> <h2> Local Weather</h2> <p class="location"></p> <p class="country"></p> <p class="fahr"></p> <p class="cels"></p> <p class="condition"></p> <p class="wtf"></p> <img src="" class="icon"> <span class="fahrToggle">Fahrenheit </span>| <span class="celsToggle">Celsius</span>
<p><br> <input type="text" class="form-control" placeholder='City, State or Country'> </input> <br> <button class="btn">Get Weather</button> </center>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Weather - Script Codes CSS Codes
body{min-width: 300px; font-family:"Courier";}
.btn{border:2px solid black; width:150px;}
.btn:hover{background-color:grey;color:white;border:2px solid grey;} p{font-size: 1.2em;}
span:hover{ cursor:pointer; background-color:black; color:white; padding:1%;}
.cels,.fahr {color:green; font-weight:bold;}
.selected{background-color:black; color:white; padding:1%;}
div{ background: rgba(255, 255, 255, 0.67); margin: 60px; padding: 20px; border-radius: 5%;
}
.form-control{width:50%;}
/*
- switch cases to display a certain photo/background depending on weather condition
*/
Weather - Script Codes JS Codes
$(document).ready(function() { // Load page showing celsius only $(".fahr").hide();
$(".celsToggle").addClass("selected"); //Load current location data $.getJSON("http://ip-api.com/json/?callback=?", function(data) { var lat = data.lat; var lon = data.lon; var city = data.city; var region = data.region; var country = data.country; // get weather data for current city var weatherCity= "http://api.openweathermap.org/data/2.5/weather?q="+city+"&appid=fb1577f7bd98d899aec2ec2e8de39c67"; $.getJSON(weatherCity, function(app) {
//convert temp in JSON from kelvin var fahr = Math.round((1.8*(app.main.temp - 273)+32)); var cels = Math.round((app.main.temp - 273)); var condition = app.weather[0].main; var conditionID = app.weather[0].id; // Change background image depending on the weather if(conditionID >=200 && conditionID<=232) { $("body").css("background-image", "url('" + "'https://4.bp.blogspot.com/-pIpbWdaxHVg/T_2qyiEpnpI/AAAAAAAAa5I/M8-D6UnCaEQ/s1600/thunder-storms.jpg'" + ")"); } else if (conditionID >=300 && conditionID<=531) { $("body").css("background-image", "url('https://4.bp.blogspot.com/_3f95iVVUx6I/TETTajgzEwI/AAAAAAAAPmA/d8RnwP5q5qM/s1600/rain-1.jpg')"); $("body").css("background-color","blue"); } else if (conditionID >=600 && conditionID<=622) { $("body").css("background-image", "url('http://ww4.hdnux.com/photos/42/05/42/8935599/5/920x920.jpg')"); } else if (conditionID >=600 && conditionID<=622) { $("body").css("background-image", "url('http://ww4.hdnux.com/photos/42/05/42/8935599/5/920x920.jpg')"); } else if (conditionID >=700 && conditionID<=771) { $("body").css("background-image", "url('https://3.bp.blogspot.com/_VBCCk_OJL3U/TLhtcMeVAXI/AAAAAAAAAYQ/kW23AUUGxJo/s1600/fog+in+trees.jpg')"); } else if (conditionID ==800) { $("body").css("background-image", "url('https://upload.wikimedia.org/wikipedia/commons/0/07/Clear_Sky.jpg')"); } else if (conditionID >=801 && conditionID<=804) { $("body").css("background-image", "url('https://seekraz.files.wordpress.com/2012/03/clouds-separating.jpg')"); } else if (conditionID >=900 && conditionID<=904 || conditionID==906) { $("body").css("background-image", "url('https://news.bbcimg.co.uk/media/images/55333000/jpg/_55333962_waves_porthcawl_wales_getty.jpg')"); } else { $("body").css("background-image", "url('https://2.bp.blogspot.com/_TAEmWG87udU/S6rPKej4COI/AAAAAAAAAo0/5rey-Z5k3Qw/s1600/20080619095031_blowing_wind.jpg')"); } //HTML $(".id").text(conditionID); $(".location").html(city//+", "+region ); $(".country").html(country); $(".fahr").html(fahr+"\xB0 F"); $(".cels").html(cels+"\xB0 C"); $(".condition").html(condition); //Fahrenheit and Celsius Toggle $(".fahrToggle").click(function () { $(".fahr").show(); $(".cels").hide(); $(".fahrToggle").addClass("selected"); $(".celsToggle").removeClass("selected"); }); $(".celsToggle").click(function () { $(".cels").show(); $(".fahr").hide(); $(".celsToggle").addClass("selected"); $(".fahrToggle").removeClass("selected"); }); }); //click button to search a new city $("button").click(function(e) { var newCity = $("input").val(); var weatherNewCity= "http://api.openweathermap.org/data/2.5/weather?q="+newCity+"&appid=fb1577f7bd98d899aec2ec2e8de39c67"; $.getJSON(weatherNewCity, function(weath) { var country = weath.sys.country; var region = data.region; var fahr = Math.round((1.8*(weath.main.temp - 273)+32)); var cels = Math.round((weath.main.temp - 273)); var condition = weath.weather[0].main; var conditionID = weath.weather[0].id; //HTML $(".id").text(conditionID); $(".location").html(newCity); $(".country").html(country); $(".fahr").html(fahr+"\xB0 F"); $(".cels").html(cels+"\xB0 C"); $(".condition").html(condition); // Change background image depending on the weather if(conditionID >=200 && conditionID<=232) { $("body").css("background-image", "url('" + "'https://4.bp.blogspot.com/-pIpbWdaxHVg/T_2qyiEpnpI/AAAAAAAAa5I/M8-D6UnCaEQ/s1600/thunder-storms.jpg'" + ")"); } else if (conditionID >=300 && conditionID<=531) { $("body").css("background-image", "url('https://4.bp.blogspot.com/_3f95iVVUx6I/TETTajgzEwI/AAAAAAAAPmA/d8RnwP5q5qM/s1600/rain-1.jpg')"); $("body").css("background-color","blue"); } else if (conditionID >=600 && conditionID<=622) { $("body").css("background-image", "url('http://ww4.hdnux.com/photos/42/05/42/8935599/5/920x920.jpg')"); } else if (conditionID >=600 && conditionID<=622) { $("body").css("background-image", "url('http://ww4.hdnux.com/photos/42/05/42/8935599/5/920x920.jpg')"); } else if (conditionID >=700 && conditionID<=771) { $("body").css("background-image", "url('https://3.bp.blogspot.com/_VBCCk_OJL3U/TLhtcMeVAXI/AAAAAAAAAYQ/kW23AUUGxJo/s1600/fog+in+trees.JPG')"); } else if (conditionID ==800) { $("body").css("background-image", "url('https://upload.wikimedia.org/wikipedia/commons/0/07/Clear_Sky.jpg')"); } else if (conditionID >=801 && conditionID<=804) { $("body").css("background-image", "url('https://seekraz.files.wordpress.com/2012/03/clouds-separating.jpg')"); } else if (conditionID >=900 && conditionID<=904 || conditionID==906) { $("body").css("background-image", "url('https://news.bbcimg.co.uk/media/images/55333000/jpg/_55333962_waves_porthcawl_wales_getty.jpg')"); } else { $("body").css("background-image", "url('https://2.bp.blogspot.com/_TAEmWG87udU/S6rPKej4COI/AAAAAAAAAo0/5rey-Z5k3Qw/s1600/20080619095031_blowing_wind.jpg')"); } //Fahrenheit and Celsius Toggle $(".fahrToggle").click(function () { $(".fahr").show(); $(".cels").hide(); $(".fahrToggle").addClass("selected"); $(".celsToggle").removeClass("selected"); }); $(".celsToggle").click(function () { $(".cels").show(); $(".fahr").hide(); $(".celsToggle").addClass("selected"); $(".fahrToggle").removeClass("selected"); }); }); });
});
});
/*
Sample weather link:
- http://api.openweathermap.org/data/2.5/weather?lat=40&lon=-75&appid=fb1577f7bd98d899aec2ec2e8de39c67
- https://codepen.io/mkarabashev/pen/xOVVvX
- https://codepen.io/Topzie/pen/QNaZJv
- https://codepen.io/MichaelMorris/pen/zGXeWr
*/
Developer | Adz |
Username | aadesida |
Uploaded | November 04, 2022 |
Rating | 3 |
Size | 3,611 Kb |
Views | 14,168 |
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 |
OA | 5,155 Kb |
LSStone Testimonials | 4,139 Kb |
LSStone Restoration | 3,873 Kb |
QuoteMachine | 3,153 Kb |
LSStone | 5,660 Kb |
Google Search Mock | 18,246 Kb |
Playful Port | 4,197 Kb |
LSStone STONEWORK | 3,954 Kb |
SoundCloud Maker | 3,468 Kb |
LSStone Patios | 4,004 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 |
Fun form with currentColor | Bnthor | 2,713 Kb |
A Pen by Patrick Cox | Pcridesagain | 2,899 Kb |
Large canvas mousemove experiment | Jibbon | 2,885 Kb |
CMP5-Opdracht15 | SannevanGastel | 2,733 Kb |
My three.js practice | Esambino | 3,203 Kb |
Weather App | Kw7oe | 3,162 Kb |
A Pen by Manoz | Manoz | 2,424 Kb |
A bit of elegance | Hackthevoid | 9,095 Kb |
Simple CSS loader. | Cabrera | 2,574 Kb |
Ipad Mini Showcase | Hornebom | 10,479 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!