cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <div class="container-fluid">
			<div class="app-box">
				<div class="app-box--search">
					<input type ="text" id="my-city" placeholder="Paris, France..."/>
					<button class="btn"  onClick="changeWeather();"><i class="fa fa-search"></i></button>
					<div class="clear-float"></div>
				</div>

				<div class="app-box--icon-box">
					<p class="info" id="location"><span id="current-city">The API used is in HTTP, your browser is blocking this API, please refresh the page from https to http.</span>, <span id="current-country"></span></p>
					<img id="current-icon" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
					<p class="icon-info"><span id="current-weather-description"></span></p>
				</div>
				<div class="app-box--temp-box">
					<button class="btn btn-circle-lg" id="switch-btn"><span id="degree-f">°F</span></button>
					<p id="temperature"><span id="current-temp"></span></p>
					<p class="weather-details">
						<span class="bold-text">Wind:</span> <span id="current-wind"></span><span id="wind"></span>
						<span id="current-wind-deg"></span><br />
						<span class="bold-text">Humidity:</span> <span id="current-humidity"></span>
					</p>
					<div id="app-box--temp-box--forecast">
						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon0" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day0"></span><br /><span id="forecast-temp-min0"></span> / <span id="forecast-temp-max0"></span><br />
									<span class="capitalize" id="forecast-temp-description0"></span><!--<br />
									Wind: <span id="forecast-wind-speed0"></span><span id="forecast-wind-dir0"></span><br />
									Humidity: <span id="forecast-humidity0"></span><br />-->
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon1" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day1"></span><br /><span id="forecast-temp-min1"></span> / <span id="forecast-temp-max1"></span><br />
									<span class="capitalize" id="forecast-temp-description1"></span>
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon2" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day2"></span><br /><span id="forecast-temp-min2"></span> / <span id="forecast-temp-max2"></span><br />
									<span class="capitalize" id="forecast-temp-description2"></span>
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon3" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day3"></span><br /><span id="forecast-temp-min3"></span> / <span id="forecast-temp-max3"></span><br />
									<span class="capitalize" id="forecast-temp-description3"></span>
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon4" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day4"></span><br /><span id="forecast-temp-min4"></span> / <span id="forecast-temp-max4"></span><br />
									<span class="capitalize" id="forecast-temp-description4"></span>
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon5" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day5"></span><br /><span id="forecast-temp-min5"></span> / <span id="forecast-temp-max5"></span><br />
									<span class="capitalize" id="forecast-temp-description5"></span>
								</p>
							</div>
						</div>

						<div class="row forescast-block">
							<div class="col-xs-5 vcenter"><img id="forescast-icon6" class="weather-icon" 	src="http://vincent-humeau.com/content/weather-app-icons/unknow.png" alt="weather icon"/>
							</div><!--
							--><div class="col-xs-7 forescast-info vcenter">
								<p>
									<span class="bold-text" id="forecast-day6"></span><br /><span id="forecast-temp-min6"></span> / <span id="forecast-temp-max6"></span><br />
									<span class="capitalize" id="forecast-temp-description6"></span>
								</p>
							</div>
						</div>

					</div>
				</div>
			</div>
			<ul id="credits">
				<li><a href="http://www.vincent-humeau.com" target="_blank"><i class="fa fa-link" aria-hidden="true"></i> By Vincent Humeau</a></li>
				<li><a href="https://www.behance.net/gallery/48402505/Free-Weather-Icons-Pack?" target="_blank"><i class="fa fa-cloud-download" aria-hidden="true"></i> Free Weather Icon Pack</a></li>
				<li><a href="https://github.com/vinceumo/fcc_weather_app" target="_blank"><i class="fa fa-github" aria-hidden="true"></i> See this project on Github</a></li>
				<li><a href="https://openweathermap.org/" target="_blank"><i class="fa fa-sun-o" aria-hidden="true"></i> API from openweathermap.org</a></li>
			</ul>
		</div>
		<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDOuZKe47ehP6nW75pkP09HkcRVo9bQClI&libraries=places"></script>
            
          
!
            
              //Mixin
@mixin transform {
	-webkit-transition: all 0.5s; /* Safari */
	transition: all 0.5s;
	transition-timing-function: ease-in-out;
}
//Color from https://color.adobe.com/KnotJustNautical-color-theme-2565165/?showPublished=true
$blue-dark: #2C3E50;
$blue-light: #6DBCDB;
$red: #FC4349;
//$red-light: lighter($red, 10%);
$grey: #D7DADB;
$grey-light: #FFFFFF;

body{
	min-height: 100vh;
	background: rgba(109,188,219,1);
	background: -moz-linear-gradient(-45deg, rgba(109,188,219,1) 0%, rgba(252,67,73,1) 100%);
	background: -webkit-gradient(left top, right bottom, color-stop(0%, rgba(109,188,219,1)), color-stop(100%, rgba(252,67,73,1)));
	background: -webkit-linear-gradient(-45deg, rgba(109,188,219,1) 0%, rgba(252,67,73,1) 100%);
	background: -o-linear-gradient(-45deg, rgba(109,188,219,1) 0%, rgba(252,67,73,1) 100%);
	background: -ms-linear-gradient(-45deg, rgba(109,188,219,1) 0%, rgba(252,67,73,1) 100%);
	background: linear-gradient(135deg, rgba(109,188,219,1) 0%, rgba(252,67,73,1) 100%);
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6dbcdb', endColorstr='#fc4349', GradientType=1 );
}
.clear-float{
	clear: both;
}
.bold-text{
	font-weight: bold;
}
.vcenter {
	display: inline-block;
	vertical-align: middle;
	float: none;
}
.weather-icon{
	max-width: 193px;
	width: 100%;
}
.capitalize{
	text-transform: capitalize;
}
.app-box{
	max-width: 400px;
	margin: 0 auto;
	margin-top: 15px;
	margin-bottom: 50px;
	text-align: center;
	background-color: $blue-dark;
	box-shadow: 8px 9px 40px -15px #000;
}
.app-box--search{
	background-color: $grey-light;
	text-align: left;
	padding: 5px 10px;
	input[type="text"]:focus, textarea:focus{
	outline: none;
	border-bottom: 1px solid $blue-light;
	}
	input{
		border: none;
		color: $blue-light;
		width: 80%;
		float: left;
		&::-webkit-input-placeholder { /* Chrome/Opera/Safari */
			color: lighten( $blue-light, 20% );
		}
		&::-moz-placeholder { /* Firefox 19+ */
			color: lighten( $blue-light, 20% );
		}
		&:-ms-input-placeholder { /* IE 10+ */
			color: lighten( $blue-light, 20% );
		}
		&:-moz-placeholder { /* Firefox 18- */
			color: lighten( $blue-light, 20% );
		}
	}
	.btn{
		background-color: $grey-light;
		color: $red;
		padding: 0;
		font-size: 1.2em;
		float: right;
	}
}
.app-box--icon-box{
	padding: 25px;
	font-size: 1em;
	.info{
		color: $grey-light;
		margin-bottom: 0;
	}
	#location{
		font-size:1.7em;
	}
	.icon-info{
		color: $grey-light;
		text-transform: capitalize;
	}
}
.app-box--temp-box{
	padding: 25px;
	position: relative;
	background-color: $grey-light;
	color: $blue-dark;
	.btn-circle.btn-lg {
		width: 50px;
		height: 50px;
		padding: 10px 16px;
		font-size: 18px;
		line-height: 1.33;
		border-radius: 25px;
	}
	#switch-btn{
		position: absolute;
		top: -30px;
		right:12px;
		display:block;
		height: 60px;
		width: 60px;
		line-height:60px;
		border-radius:50%;
		background-color: $red;
		color: $grey-light;
		box-shadow: 8px 9px 40px -7px #000;
		font-size: 20px;
		font-weight: 400;
		padding: 0;
		@include transform ;
		&:hover{
			box-shadow: 8px 9px 40px -1px #000;
		}
	}
	p{
		margin: 0;
	}
	#temperature{
		font-size: 6em;
	}
	.weather-details{
		margin-bottom: 25px;
	}
}
#app-box--temp-box--forecast{
	padding: 0 20px;
	margin-top: 50px;
	.forescast-block{
		margin-bottom: 25px;
		display: flex;
	}
	.forescast-img{
		width: 100%;
	}
	.forescast-info{
			display:flex;
			align-items:center;
		p{
			text-align: left;
			line-height: 1.05;

		}
	}
}
#credits{
	list-style-type: none;
	text-align: center;
	padding-left: 0;
	a{
		color: $grey-light;
		font-weight: normal;
	}
}


@media screen and (max-width: 295px) {
	.app-box--icon-box{
		padding: 5px;
	}
	.app-box--temp-box{
		padding: 5px;
		#temperature{
			font-size: 4em;
			margin-bottom: 5px;
			margin-top: 20px;
		}
	}
}
            
          
!
            
              var ipUrl = 'http://ip-api.com/json/';
var lat ='';
var lon ='';
var newLocation ='';
var openWeatherApiKey = 'a3669d1484b9378d17f7c339e446746d';
var openWeatherApiCurrent = 'http://api.openweathermap.org/data/2.5/weather?&appid='+openWeatherApiKey;
var openWeatherApiForecast = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=&appid='+openWeatherApiKey;
var metric = 'metric';
var imperial = 'imperial';
var unit = '&units='+metric;
var today = new Date();
var icons = ['00broken-clouds.png','01clear-sky-day.png','02clear-sky-night.png','03few-clouds-day.png','04few-clouds-night.png','05light-rain-day.png','06light-rain-night.png','07mist-day.png','08mist-night.png','09scattered-clouds-day.png','10scattered-clouds-night.png','11shower-rain.png','12snow.png','13thunderstorm.png'];
var urlIcons = 'http://vincent-humeau.com/content/weather-app-icons/';

LocalWeather();

function LocalWeather(){
	$.getJSON(ipUrl, function(data) {
		lat = data.lat;
		lon = data.lon;
		var LocalWeather = '&lat=' + lat + '&lon=' + lon;
		var openWeatherCurrentUrl = openWeatherApiCurrent + LocalWeather + unit;
		var openWeatherForecastUrl = openWeatherApiForecast + LocalWeather +unit;
		currentForecastWeather(openWeatherCurrentUrl, openWeatherForecastUrl);
	});
}

function currentForecastWeather(currentURL, forecastURL){
	$.getJSON(currentURL, function(data){
		$("#current-city").html(data.name);
		$("#current-country").html(data.sys.country);
		changeIcon(data.weather[0].icon, "#current-icon");
		$("#current-weather-description").html(data.weather[0].description);
		$("#current-temp").html(Math.round(data.main.temp * 10)/10 +'°C');
		$("#current-wind").html(data.wind.speed + ' meter/s');
		$("#current-wind-deg").html(degToCompass(data.wind.deg));
		$("#current-humidity").html(data.main.humidity + '%');
		$.getJSON(forecastURL, function(data){
			for (var i=0; i<7; i++) {
				changeIcon(data.list[i].weather[0].icon, "#forescast-icon"+i);
				dayOfWeek(data.list[i].dt,"#forecast-day"+i)
				$("#forecast-temp-min"+i).html(Math.round(data.list[i].temp.min * 10)/10 + '°C');
				$("#forecast-temp-max"+i).html(Math.round(data.list[i].temp.max * 10)/10 + '°C');
				$("#forecast-temp-description"+i).html(data.list[i].weather[0].description);
			}
			$('#switch-btn').click(function(){
				if($(this).text() === '°F'){
					for (var i=0; i<7; i++) {
						$(this).text('°C');
						$("#forecast-temp-min"+i).html(Math.round(((data.list[i].temp.min*2)+30) * 10)/10 + '°F');
						$("#forecast-temp-max"+i).html(Math.round(((data.list[i].temp.max*2)+30) * 10)/10 + '°F');
					}
				}
				else {
					for (var i=0; i<7; i++) {
						$(this).text('°F');
						$("#forecast-temp-min"+i).html(Math.round(data.list[i].temp.min * 10)/10 + '°C');
						$("#forecast-temp-max"+i).html(Math.round(data.list[i].temp.max * 10)/10 + '°C');
					}
				}
			});
		});
		$('#switch-btn').click(function(){
			if($(this).text() === '°F'){
				$("#current-temp").html(Math.round(((data.main.temp*2)+30) * 10)/10 + '°F');
				$("#current-wind").html(Math.round((data.wind.speed)*2.23694) + ' miles/h');
			}
			else {
				$("#current-temp").html(Math.round(data.main.temp * 10)/10 + '°C');
				$("#current-wind").html(data.wind.speed + ' meter/s');
			}
		});
	});
}
function changeIcon(iconVar, iconDestination){
	switch (weatherIcon = iconVar) {
		case weatherIcon = '01d':
			$(iconDestination).attr("src",urlIcons+icons[1]);
			break;
		case weatherIcon = '01n':
			$(iconDestination).attr("src",urlIcons+icons[2]);
			break;
		case weatherIcon = '02d':
			$(iconDestination).attr("src",urlIcons+icons[3]);
			break;
		case weatherIcon = '02n':
			$(iconDestination).attr("src",urlIcons+icons[4]);
			break;
		case weatherIcon = '03d':
			$(iconDestination).attr("src",urlIcons+icons[9]);
			break;
		case weatherIcon = '03n':
			$(iconDestination).attr("src",urlIcons+icons[10]);
			break;
		case weatherIcon = '04d':
		case weatherIcon = '04n':
			$(iconDestination).attr("src",urlIcons+icons[0]);
			break;
		case weatherIcon = '09d':
		case weatherIcon = '09n':
			$(iconDestination).attr("src",urlIcons+icons[11]);
			break;
		case weatherIcon = '10d':
			$(iconDestination).attr("src",urlIcons+icons[5]);
			break;
		case weatherIcon = '10n':
			$(iconDestination).attr("src",urlIcons+icons[6]);
			break;
		case weatherIcon = '11d':
		case weatherIcon = '11n':
			$(iconDestination).attr("src",urlIcons+icons[13]);
			break;
		case weatherIcon = '13d':
		case weatherIcon = '13n':
			$(iconDestination).attr("src",urlIcons+icons[12]);
			break;
		case weatherIcon = '50d':
			$(iconDestination).attr("src",urlIcons+icons[7]);
			break;
		case weatherIcon = '50n':
			$(iconDestination).attr("src",urlIcons+icons[8]);
			break;
		default:$(iconDestination).attr("src",urlIcons+icons[1]);
		break;
	}
}
function degToCompass(i) {
	var dir = Math.floor((i / 22.5) + 0.5);
	var arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
	if (i == null){
		return '';
	}
	else{
		return ' - '+arr[(dir % 16)];
	}
}
function dayOfWeek(dt,dayDestination) {
	var weekday = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
	var day = new Date(dt*1000); //*1000 to put it msecond
	$(dayDestination).html(weekday[day.getDay()]);
}

function initializeGeocoding() {
	var autocomplete = new google.maps.places.Autocomplete((document.getElementById('my-city')), {
		types: ['(cities)']
	});
}
$(document).keypress(function(e) {
	if(e.which == 13) {
		changeWeather();
}
});
function changeWeather() {
	geocoder = new google.maps.Geocoder();
	var address = document.getElementById("my-city").value;
	geocoder.geocode( { 'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			lat = results[0].geometry.location.lat();
			lon = results[0].geometry.location.lng();
			var LocalWeather = '&lat=' + lat + '&lon=' + lon;
			var openWeatherCurrentUrl = openWeatherApiCurrent + LocalWeather + unit;
			var openWeatherForecastUrl = openWeatherApiForecast + LocalWeather +unit;
			currentForecastWeather(openWeatherCurrentUrl, openWeatherForecastUrl);
		}

		else {
			alert("Geocode was not successful for the following reason: " + status);
		}
	});
}
google.maps.event.addDomListener(window, 'load', initializeGeocoding);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console