Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
	<div class="weather_card">
		<div class="row">
			<div class="large-12 columns">
				<h1 class="text-center"><strong>Local Weather</strong></h1>
				<h3 id="position" class="text-center"></h3>
			</div>
		</div>
		<div class="row text-center">
			<div class="large-6 columns">
				<h3>Current Weather</h3>
				<h1><i id="icon"></i></h1>
				<h4 id='current_w'></h4>
				<h4 id='current_temp'></h4>
			</div>
			<div class="large-6 columns">
				<h3>Daily Forecast</h3>
				<ul id="details">

				</ul>
			</div>
		</div>
	</div>
</div>
<div class="large-12 columns text-center sticky">
	<p> dynamic background images provided by <a href="https://source.unsplash.com" targe="_blank">source.unsplash</a> </p>
	<p> weather icons care of <a href="https://weathericons.io" target="_blank">weathericons.io</a>
</div>
              
            
!

CSS

              
                body {
	background-image: url('https://source.unsplash.com/featured/?weather');
	background-repeat: no-repeat;
	background-size: cover;
	color: #fff;
}

.container {
	//margin: 50px 0px;
	padding: 50px 0px;
	min-height: 100%;
}

.weather_card {
	background:rgba(255,255,255,0.7);
	color: #000;
	border-radius: 10px;
	min-width:400px;
	max-width:800px;
	margin: auto;
	padding:20px 40px 40px 20px;
}

.high {
	color: blue;
}

.low {
	color: red;
}

#details li {
	list-style: none;
}

              
            
!

JS

              
                function titleCase(str) {
  var strArray = str.split(" ");
  var output = new Array;
  for (var i = 0; i < strArray.length; i++){
  output.push( strArray[i].replace( /\w'?\S*/, function(word){
    return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
    }));
    
  }
  return output.join(" ");
}

function getIcon(main,sunrise,sunset) {
  var now = Math.round(new Date().getTime()/1000);
  var icon = "wi wi-";

  icon += (now > sunrise && now < sunset ) ? "day-" : "night-";

  switch(true){
    case (main < 300):
      icon += "thunderstorm"; //thunderstorm
      break;
    case (main < 400):
      icon += "showers"; //drizzle
      break;
    case (main < 600):
      icon += "rain"; //rain
      break;
    case (main < 700):
      icon += "snow"; // snow
      break;
    case (main < 800):
      icon = "wi-smoke"; //fog/haze/sandstorm/ash
      break;
    case (main == 800):
      icon += (now > sunrise && now < sunset ) ? "sunny" : "night-clear";
      break;
    case (main < 805):
      icon += "cloudy"; //clouds
      break;
    case (main < 903):
      icon = "wi-hurricane"; //cyclone
      break;
    case (main < 905):
      icon = "wi-thermometer"; //temperature
      break;
    case (main == 905):
      icon = "wi-strong-wind"; //windy
      break;
    case (main == 906):
      icon = "wi-hail"; //hail
      break;
    case (main < 957):
      icon += "cloudy-gusts"; //breeze
      break;
		case (main <= 963 ):
      icon += "storm-showers"; // storm
			break;
    default:
      icon = "wi-alien";
    }
  return icon;
}

$(document).ready(function() {

	$.getJSON("https://geoip-db.com/json/geoip.php?jsonp=?", function(position) {
		var lat,lon,city,zip,current_weather,current_temp,icon,unsplash,daily,min_temp,max_temp,temps,current_api_url,forecast_api_url;
		var ow_api = "85d3be3684ef7f65d6f54b6fe32ac79d";

		lat = position.latitude;
		lon = position.longitude;
		city = position.city;
		zip = position.postal;
		current_api_url = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=imperial&appid=" + ow_api;
		forecast_api_url = "http://api.openweathermap.org/data/2.5/forecast/daily/?lat=" + lat + "&lon=" + lon + "&cnt=1&units=imperial&appid=" + ow_api;
		console.log(current_api_url);
		$.getJSON(current_api_url, function(weather) {
			current_weather = weather.weather[0].description;
			current_temp = Math.round(weather.main.temp) + "&deg";
			unsplash = "url('https://source.unsplash.com/featured/?" + weather.weather[0].main + "')";
			//icon = "wi-" + weather.weather[0].main.toLowerCase();
			icon = getIcon(weather.weather[0].id);
			
			$('body').css("background-image", unsplash );
			$('#position').html(city + ", " + zip);
			$('#icon').addClass(icon);
			$('#current_w').html(titleCase(current_weather));
			$('#current_temp').html(current_temp);
		});
		
		$.getJSON(forecast_api_url, function(forecast){
			daily = "<li> " + titleCase(forecast.list[0].weather[0].description) + "</li>";
			//min_temp ="<li> min: " + Math.round(forecast.list[0].temp.min) + "&deg</li>";
			//max_temp ="<li> max: " + Math.round(forecast.list[0].temp.max) + "&deg</li>";
			min_temp = Math.round(forecast.list[0].temp.min);
			max_temp = Math.round(forecast.list[0].temp.max);
			
			temps = '<li><span class="low">' + min_temp + '&deg;</span> / <span class="high">' + max_temp + '&deg;</span> </li>'
			
			//$('#details').html(daily + min_temp + max_temp);
			$('#details').html(daily + temps);
		});
			
	});

});
              
            
!
999px

Console