Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
 <div class="row">
  <div class="jumbotron weatherjumbo">
	  <div id="data" style="height:30px"></div>
  <h2 id="loc"></h2>
	 <canvas id="icon" width="200" height="200" class="hidden-sm hidden-xs"></canvas>
	  <canvas id="icon2" width="80" height="80" class="hidden-lg hidden-md"></canvas>
	  <br />
  <h3 id="json"></h3>
	  <br />
  <p id="prev"></p>
	 </div>


  <label for="units" class="checkbox">
	  <span class="switch">
	  <input type="checkbox" id="units" checked class="checkbox" />
	  
	  	<span class="switch-container">
			<span class="on">°C</span>
	  		<span class="mid"></span>
	  		<span class="off">°F</span>
		</span>
	  </span>
	 </label>
	 <br />
	 
	 <label for="lang" class="checkbox">
	  <span class="switch">
	  <input type="checkbox" id="lang" checked class="checkbox" />
	  
	  	<span class="switch-container">
			<span class="on">FR</span>
	  		<span class="mid"></span>
	  		<span class="off">ENG</span>
		</span>
	  </span>
	 </label>

 </div>
	<div class="loader"></div>
	
</div>
<script src="https://rawgithub.com/darkskyapp/skycons/master/skycons.js"></script>
            
          
!
            
              @import "compass";
$default-transition-duration:.3s;

.loader {
	margin:0 auto;
	margin-top: 30px;
    border: 8px solid #f3f3f3; /* Light grey */
    border-top: 8px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.weatherjumbo {
	position: relative;
	background-color: rgba(0,0,0,0.9);
	color: #FFF;
	margin-top: 20px;
	canvas {
		position: absolute;
		right: 20px;
		top: 20px;
	}
}

.checkbox input {
 display: none;
}

.checkbox {
	width: 111px;
	margin: 0 auto;
 .rounded {
  background-color: #fff;
  border: 3px solid #bdc3c7;
  height: 17px;
  width: 17px;
  display: inline-block;
  vertical-align: middle;
  @include border-radius(16px);
  position: relative;
  margin-left: -20px;
 }
 input:checked+.rounded {
  border-color: #2ecc71;
  &:after {
   content: "";
   display: block;
   width: 5px;
   height: 5px;
   background-color: #2ecc71;
   position: absolute;
   top: 3px;
   left: 3px;
   @include border-radius(2px);
  }
 }

}

.switch {	
	display: inline-block;
	vertical-align: middle;
	margin-left: -20px;
	width: 145px;
	height: 30px;
	overflow: hidden;
	-webkit-mask:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJEAAAAfCAYAAADnYi+LAAACGElEQVR4nO2cQa6iQBCGC1hpaFwpVxAOACEonEDP9M7BCQQTO4ErcAabPoIxMVHXdM3ixZlxMuOgL5m2M/Ul37KTn6QWBV2FhYgIA+i6DpqmgbZtYb/fw/F4hPP5POQoYQCTyQSm0ykEQQDL5RJWqxXM5/Nhh/EBSinknGMcxwgA5H9mHMfIOUel1KMywT8WkZQS8zzX/iCkfvM8x67rniuiqqrQdV3t4cn30XVdrKpqWBEVRYG2bWsPTb6ftm1jURSPi2i73aLjONrDku+r4zhYluXvi0hKiYwx7SHJ95cxhlLK+yJSSlETTT5lnuff39oAEZFzrj0UaZ6c8x9FlCSJ9kCkeSZJgoiIlhACgyAAgngFIQTYTdPozkEYTF3X4IxGow8ppe4shKGMx2Nw+r7/OJ1OurMQhtL3PVie5+HlctGdhTAUz/PAgs9OmyBexvY8T3cGwmAYY2DPZjPdOQiD8X0f7DAMdecgDCYMQ7DTNNWdgzCYNE2BvlgTX0IIAYCINENNvuTt7oxu8cmXvbvFV0phlmXaQ5HmmGXZ/TzRbbKRhvPJIbque7f9cTdjXZYlzViTD3UcBzebDW17kK85aNvjBu2dkb/61N7Zzz0SNdskwGcT/fQG7I3bLn4URdofhPz3RlGEu93ur7v4FuLwv4LUdQ1t24IQAg6HA1yv1yFHCQNgjIHv+xAEASwWC1iv14P/CvINGl5BTyMeSRgAAAAASUVORK5CYII=');
	@include border-radius(40px);
	.switch-container {
		position: relative;
		top: 0px;
		left: 0px;
		display: inline-block;
		width: 260px;
		height: 30px;
		margin-left: -115px;
	}
	.on, .off{
		display: inline-block;
		float: left;
		background-color: #2ecc71;
		width: 50%;
		height: 30px;
		padding: 4px 0;
		text-align: center;
		color: #fff;
		position: relative;
		z-index: 1;
	}
	.on {
		@include border-left-radius(40px);
	}
	.off {
		@include border-right-radius(40px);
		background-color: #e74c3c;
	}
	.mid	{
		display: inline-block;
		width: 30px; height: 30px;
		@include border-radius(40px);
		background-color: #FFF;
		margin-left: -15px;
		margin-right: -15px;
		position: relative;
		z-index: 2;
		float: left;
		border: 4px solid #e74c3c;
	}
	input:checked + .switch-container {
		margin:0 auto;
		.mid{
			border-color: #2ecc71;			
		}
	}
}
            
          
!
            
              $(document).ready(function() {
	$('.loader').hide();
	var body = $("body");
	var skycons = new Skycons({"color": "white"});

	$("#units").click(function() {
		checkUnits();
	});
	$("#lang").click(function() {
		checkLang();
	});
	var units = "&units=si";
	var lang = "lang=fr";
	function getWeather() {
		
		$('.loader').show();
		
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(function(position) {
				var lat = position.coords.latitude, lon = position.coords.longitude;
				var api = "AIzaSyCyS1_lM1uUkruHyeSHcOo7s0FUJ0lMFDw";
				var url =
					"https://crossorigin.me/https://api.darksky.net/forecast/" +
					api +
					"/" +
					lat +
					"," +
					lon +
					"?" +
					lang +
					units;

				console.log(url);

				$.getJSON(url, function(data) {
					var temp = "";
					if (units == "") {
						temp = "°F";
					}
					if (units == "&units=si") {
						temp = "°C";
					}
					$("#json").html(						
							data.currently.temperature +
							temp
					);
					switch(lang){
						case "lang=fr":
							$("#prev").html(
						"Les prévisions pour demain sont: " + data.hourly.summary
					);
							break;
						case "":
							$("#prev").html(
						"Tomorrow's forecast: " + data.hourly.summary
					);
								  }
					
					switch (data.currently.icon) {
						case "clear-day":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/clear_day.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.CLEAR_DAY);
							skycons.play();
							break;
						case "clear-night":
							body
								.css(
									"background-image",									"url(http://julienjovy.free.fr/portfolio/ressources/clear_night.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.CLEAR_NIGHT);
							skycons.play();
							break;
						case "rain":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/rain.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.RAIN);
							skycons.play();
							break;
						case "snow":
						case "sleet":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/snow.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.SNOW);
							skycons.play();
							break;							
							
						case "wind":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/wind.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.WIND);
							skycons.play();
							break;
							
						case "fog":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/fog.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.FOG);
							skycons.play();
							break;
							
							case "cloudy":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/cloudy.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.CLOUDY);
							skycons.play();
							break;
							
							case "partly-cloudy-day":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/partly_cloudy_day.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.PARTLY_CLOUDY_DAY);
							skycons.add("icon2", Skycons.PARTLY_CLOUDY_DAY);
							skycons.play();
							break;
							
							case "partly-cloudy-night":
							body
								.css(
									"background-image",
									"url(http://julienjovy.free.fr/portfolio/ressources/partly_cloudy_night.jpg)"
								)
								.css("background-size", "cover");
							skycons.add("icon", Skycons.PARTLY_CLOUDY_NIGHT);
							skycons.play();
							break;					
							
														
					}
					$('.loader').hide();
				});

				$.getJSON(
					"https://maps.googleapis.com/maps/api/geocode/json?latlng=" +
						lat +
						"," +
						lon +
						"&key=AIzaSyCyS1_lM1uUkruHyeSHcOo7s0FUJ0lMFDw",
					function(google) {
						$("#loc").html(
								google.results[0].address_components[2].long_name +
								", " +
								google.results[0].address_components[4].long_name
						);
					}
				);
			});
		} else {
			$('.loader').hide();
			$('#prev').html("La geolocalisation doit être active pour utiliser pleinement cette application")
		}
	
	
	
		

	getWeather();
	function checkUnits() {
		if (document.getElementById("units").checked === false) {
			units = "";
		} else if (document.getElementById("units").checked === true) {
			units = "&units=si";
		}
		getWeather();
	}
	function checkLang() {
		if (document.getElementById("lang").checked === false) {
			lang = "";
		} else if (document.getElementById("lang").checked === true) {
			lang = "lang=fr";
		}
		getWeather();
	}
	
	
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console