cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              	<body>
		<div id="container">
				<h1 id="currentTemp"></h1>
				<h5 id="max-min"></h5>
				<h5> <a href="#" id="toggle">toggle °C/°F</a></h5>
				<h3 id="currentWeather"></h3>
				<h5 id="windSpeed"></h5>
				<h3 id="currentLocation">Finding location...</h3>
		</div>
	</body>
            
          
!
            
              body {
  background: gray;
	background-size: 100% 100%;
	min-height: 100vh;
	display: flex;
	align-items: center;
}

#container {
	background: rgba(50, 50, 50, 0.6);
	margin: 0 auto;
	width: 220px;
	border-radius: 10px;
	padding: 20px;
	text-align: center;
	color: white;
	
}

#currentTemp {
	margin: 5px;
}

a {
  transition: color .6s;
  color: #66CDAA;
  text-decoration: none;
}

a:link,
a:visited { 
color: 	#66CDAA; 
text-decoration: none;
font-weight: bold
}
a:hover   {
	color: cyan;
	text-decoration: none;
	font-weight: bold
	}
	
a:active  {
  color: cyan;
  text-decoration: none;
  font-weight: bold
}

            
          
!
            
              $(document).ready(function(){
 
	var API_KEY = "726d0e3f3844816dae9fca7fe6c10366";
	var loc;
	var farenheit = false;
	var wd;
	
	function displayTemp(cTemp, f){
		if (f){
			return Math.round((cTemp*1.8) + 32) + "&#8457;";
		}
		else {
			return Math.round(cTemp) + "&#8451;";
		}
	}
 
	function render (wd, farenheit){
				var icon = wd.weather[0].icon;
				var currentTemp = displayTemp(wd.main.temp, farenheit);
				var dayHigh = displayTemp(wd.main.temp_max, farenheit);
				var dayLo = displayTemp(wd.main.temp_min, farenheit);
				var currentWeather = wd.weather[0].main;
				var windSpeed = (wd.wind.speed*2.237).toFixed(1);
				var currentLocation = wd.name;
				var currentCountry = wd.sys.country;
				
				$('#currentTemp').html(currentTemp);
				$('#max-min').html("Max: " + dayHigh + ", Min: " + dayLo);
				$('#currentWeather').html(currentWeather);
				$('#windSpeed').html("Wind Speed: " + windSpeed + " mph");
				$('#currentLocation').html(currentLocation + ", " + currentCountry);
				
				var iconSrc = "http://openweathermap.org/img/w/" + icon + ".png";
				$("#currentTemp").prepend("<img src='" + iconSrc + "'>");
				
				if (icon == "01d"){
					// clear day
					$('body').css('background-image','url("https://i.imgsafe.org/ab8ba571b3.jpg")');
				}
				
				else if(icon == "01n"){
					//clear night
					$('body').css('background-image','url("https://i.imgsafe.org/ab8bb00c47.jpg")');
				}
				
				else if (icon == "02d" || icon == "02n"){
					//few clouds
					$('body').css('background-image','url("https://i.imgsafe.org/ab8bc82f58.jpg")');
				}

								
				else if (icon == "03d" || icon == "03n"){
					//scattered clouds
					$('body').css('background-image','url("https://i.imgsafe.org/ab939b5830.jpg")');
				}
				
								
				else if (icon == "04d" || icon == "04n"){
					//broken clouds
					$('body').css('background-image','url("https://i.imgsafe.org/ab8b7a3bda.jpg")');
				}
				

				else if (icon == "11d" || icon == "11n"){
					//thunderstorm
					$('body').css('background-image','url("https://i.imgsafe.org/ab93727606.jpg")');
				}

				
				else if (icon == "13d" || icon == "13n"){
					//snowy
					$('body').css('background-image','url("https://i.imgsafe.org/ab938dcb9f.jpg")');
				}
				
				else if (icon == "50d" || icon == "50n"){
					//misty
					$('body').css('background-image','url("https://i.imgsafe.org/ab9349879a.jpg")');
				}
				
				else {
					//rain
					$('body').css('background-image','url("https://i.imgsafe.org/ab935c28c7.jpg")');
				}
				
	}
 
	$.getJSON("http://ipinfo.io", function(data) {
		loc = data.loc.split(",");
		
		$.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + loc[0] + "&lon=" + loc[1] + "&units=metric&APPID=" + API_KEY, 
		
			function(apiData){
				
				wd = apiData;
				
				render(apiData, farenheit);
				
				$('#toggle').click(function(){
				farenheit = !farenheit;
				render(wd, farenheit);
			});
					
			}
		);
	});
});


            
          
!
999px
Loading ..................

Console