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

              
                $(document).ready( function(){

    var lat;
    var lon;
    var city;
    var zip;
    var currentWeather;
    var currentTemp;
		var sunrise;
		var sunset;
    var icon;
    var unsplash;
    var daily;
    var minTemp;
    var maxTemp;
    var currentAPI;
    var forecastAPI;
    var ow_api = "85d3be3684ef7f65d6f54b6fe32ac79d";
    var locationAPI = "https://geoip-db.com/json/geoip.php?jsonp=?";

    // Get Location Information

    $.getJSON(locationAPI)
			.done (function(location){
        lat = location.latitude;
        lon = location.longitude;
        city = location.city;
        zip = location.postal;
        currentAPI = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + ow_api;
        forecastAPI = "http://api.openweathermap.org/data/2.5/forecast/daily/?lat=" + lat + "&lon=" + lon + "&cnt=1&appid=" + ow_api;
    });

    // openweathermap API calls

    // Current Weather

    $.getJSON(currentAPI, function(current){
        currentWeather = current.weather[0].description;
        currentTemp = convertTemp(current.main.temp,"f");
				sunrise = current.sys.sunrise;
				sunset = current.sys.sunset;
        unsplash = "url('https://source.unsplash.com/featured/?" + current.weather[0].main + "')";
        icon = getIcon(current.weather.weather[0].id, sunrise, sunset);
    })

		// Daily Forecast

		$.getJSON(forecastAPI, function(daily){
			daily = daily.list[0].weather[0].description;
			minTemp = daily.list[0].temp.min;
			maxTemp = daily.list[0].temp.max;
		})

	// Update Page with Information
	
	$("#position").html(city + ", " + zip);
	$("#icon").html(icon);
	

	//helpers
	function convertTemp(kelvin,arg) {
			if (arg == "f") {
					return Math.round((kelvin*(9/5))-459.67);
			} else {
					return Math.round(kelvin - 273.15);
			}
	}

	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;
	}
	

});
              
            
!
999px

Console