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="Weather row center">
  <div class="Weather__main column column-center split-center"> <!-- Begin Main Bubble -->
    
    <h3>Local Weather</h3>
    <h2 id="location">Your Location</h2>
    <span id="temp">70</span>
    <div class="row center column-center Weather__main-toggle"> <!-- Begin Unit Switch -->
      <span>F</span>
      <button id="unit-switch"><span id="unit-toggle"></span></button>
      <span>C</span>
    </div> <!-- End Unit Switch -->
    
  </div> <!-- End Main Bubble -->
  
  <div class="Weather__right column-split"> <!-- Begin Right Side Bubbles -->
    
    <div class="Weather__right-icon"> <!-- Begin Icon Bubble -->
      <div class="column column-center"> <!-- Begin Current Coverage -->
        <i id="icon" class="wi wi-day-sunny"></i>
        <span id="coverage">Sunny</span>
      </div> <!-- End Current Coverage -->
    </div> <!-- End Icon Bubble -->
    <div class="Weather__right-time column center column-center"> <!-- Begin Time Bubble -->
      <span id="time">15:00</span>
    </div> <!-- End Time Bubble -->
    <div id="refresh" class="Weather__right-refresh column center column-center">
      <span>Refresh</span>
    </div>
    
  </div> <!-- End Right Side Bubbles -->
</div>
              
            
!

CSS

              
                // Fonts
@import url(https://fonts.googleapis.com/css?family=Lato:400,300,700);
@import url(https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.css);

// Mixins
@mixin size($point) {
	@if $point == small {
		@media screen and (min-width: 500px) {
			@content;
		}
	}
	@if $point == large {
		@media screen and (min-width: 880px) {
			@content;
		}
	}
}

// Resets
* {
	box-sizing: border-box;
	padding: 0;
	margin: 0;
}

html, body {
	height: 100%;
}

body {
	overflow-x: hidden;
	font-family: 'Lato', sans-serif;
	padding-top: 80px;
	color: #fff;
	background: #333;
}

// Globals
.row {
	display: flex;
}

.column {
	display: flex;
	flex-direction: column;
}

.center {
	justify-content: center;
}

.column-center {
	align-items: center;
}

.split {
	justify-content: space-between;
}

.split-center {
	justify-content: space-around;
}

// Animations
@keyframes fadeOne {
	0% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}

@keyframes fadeTwo {
	0% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}

// Page Styles
.Weather {
	min-width: 350px;
  // Main Bubble
	&__main {
		background: #71db71;
		width: 250px;
		height: 250px;
		border-radius: 50%;
		border: 4px solid #fff;
		text-align: center;
		padding: 30px 0 15px;
		@include size(small) {
			width: 300px;
			height: 300px;
		}
		@include size(large) {
			width: 350px;
			height: 350px;
		}
	}
  // Local Weather Header
	h3 {
		font-size: 1.3rem;
		font-weight: 300;
		@include size(small) {
			font-size: 1.7rem;
		}
		@include size(large) {
			font-size: 2rem;
		}
	}
  // Location Text
	h2 {
		font-size: 1.5rem;
		font-weight: 400;
		@include size(small) {
			font-size: 2rem;
		}
		@include size(large) {
			font-size: 2.425rem;
		}
	}
	#temp {
		font-size: 3rem;
		display: inline-block;
		position: relative;
		animation: fadeOne .4s;
		@include size(small) {
			font-size: 3.4rem;
		}
		@include size(large) {
			font-size: 4rem;
		}
		&:after {
			content: '';
			position: absolute;
			top: 11px;
			right: -16px;
			height: 7px;
			width: 7px;
			border: 3px solid #fff;
			border-radius: 50%;
			@include size(large) {
				height: 10px;
				width: 10px;
				top: 16px;
				right: -17px;
			}
		}
		&.toggle {
			animation: fadeTwo .4s;
		}
	}
  // Unit Toggle
	&__main-toggle {
		margin: 0 0 0 16px;
		& > span {
			font-size: 1.2rem;
			position: relative;
			@include size(small) {
				font-size: 1.5rem;
			}
			@include size(large) {
				font-size: 1.7rem;
			}
			&:before {
				content: '';
				position: absolute;
				left: -10px;
				top: 6px;
				height: 3px;
				width: 3px;
				border: 2px solid #fff;
				border-radius: 50%;
				@include size(large) {
					width: 4px;
					height: 4px;
					top: 7px;
				}
			}
			&:last-child {
				margin-left: 11px;
			}
		}
    // Toggle Switch
		button {
			background: #6bbf6b;
			border: none;
			border-radius: 30px;
			outline: none;
			width: 45px;
			height: 20px;
			margin: 5px 5px 0;
			cursor: pointer;
			position: relative;
			transition: background .2s;
			@include size(small) {
				height: 25px;
				width: 55px;
			}
			@include size(large) {
				height: 30px;
				width: 65px;
			}
			&:active {
				background: #67b567;
			}
			#unit-toggle {
				position: absolute;
				display: inline-block;
				left: 3px;
				top: .13em;
				width: 15px;
				height: 15px;
				background: #fff;
				border-radius: 50%;
				transition: left .2s;
				@include size(small) {
					height: 20px;
					width: 20px;
				}
				@include size(large) {
					height: 24px;
					width: 24px;
					top: 3px;
					left: 4px;
				}
				&.toggle {
					left: 27px;
					@include size(small) {
						left: 32px;
					}
					@include size(large) {
						left: 37px;
					}
				}
			}
		}
	}
  // Right Side Bubbles
	&__right {
		&-icon, &-time, &-refresh {
			background: #71db71;
			border-radius: 50%;
			border: 3px solid #fff;
			position: relative;
			&:before {
				content: '';
				position: absolute;
				height: 6px;
				width: 50px;
        background: #fff;
				z-index: -1;
			}
		}
		&-icon {
			width: 100px;
			height: 100px;
			@include size(small) {
				width: 120px;
				height: 120px;
			}
			@include size(large) {
				width: 130px;
				height: 130px;
			}
			&:before {
				left: -30px;
				top: 70px;
				transform: rotate(-30deg);
				@include size(small) {
					top: 80px;
				}
			}
			#icon {
				margin: 20px 0 5px 2px;
				font-size: 2.3rem;
				@include size(small) {
					font-size: 3.2rem;
					margin-top: 20px;
				}
				@include size(large) {
					font-size: 3.5rem;
				}
			}
      // Coverage Text
			#coverage {
				font-size: 1rem;
				@include size(small) {
					font-size: 1.05rem;
				}
				@include size(large) {
					font-size: 1.2rem;
				}
			}
		}
		&-time {
			width: 85px;
			height: 85px;
			font-size: 1.5rem;
			margin: 20px 0 5px 15px;
			@include size(small) {
				width: 100px;
				height: 100px;
				font-size: 1.8rem;
			}
			@include size(large) {
				width: 115px;
				height: 115px;
				font-size: 2rem;
			}
			&:before {
				top: 32px;
				left: -30px;
				@include size(small) {
					top: 38px;
				}
				@include size(large) {
					top: 47px;
				}
			}
		}
		&-refresh {
			width: 65px;
			height: 65px;
			margin-left: -20px;
			padding-bottom: 5px;
			cursor: pointer;
			transition: background .2s;
			@include size(small) {
				width: 75px;
				height: 75px;
			}
			@include size(large) {
				width: 80px;
				height: 80px;
			}
			&:hover {
				background: #6ed36e;
			}
			&:active {
				background: #6ac96a;
			}
			&:before {
				top: -4px;
				left: -30px;
				transform: rotate(40deg);
			}
			span {
				font-size: .95rem;
				@include size(small) {
					font-size: 1.1rem;
				}
				@include size(large) {
					font-size: 1.2rem;
				}
			}
		}
	}
}
              
            
!

JS

              
                (function() {

  var Weather = {
    init: function() {
      this.getLocation();
      this.showTime();
      $('#unit-switch').on('click', this.changeUnit);
      $('#refresh').on('click', this.refresh);
    },

    cache: {
      showFahrenheit: true,
    },

    getLocation: function() {
      var c = Weather.cache;

      if (window.chrome) {
        $.getJSON('http://ip-api.com/json', function(json) {
          c.lat = json.lat;
          c.long = json.lon;
          Weather.getInformation();
        });
      } else {
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(data) {
            c.lat = data.coords.latitude;
            c.long = data.coords.longitude;
            Weather.getInformation();
          });
        }
      }

    },

    getInformation: function() {
      var c = Weather.cache;

      $.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + c.lat + '&lon=' + c.long + '&units=imperial&appid=3acc16ffae9e45df92a064e41646355f', function(json) {

        c.location = json.name;
        c.country = json.sys.country;
        c.fahrenheit = Math.round(json.main.temp);
        c.celcius = Math.round((c.fahrenheit - 32) * 5 / 9);
        c.icon = json.weather[0].id;
        c.coverage = json.weather[0].main;
        c.sunrise = json.sys.sunrise;
        c.sunset = json.sys.sunset;

        Weather.showMainInformation();
        Weather.showCurrentCoverage();
      });
    },

    showMainInformation: function() {
      var c = Weather.cache;

      // Show Location
      $('#location').html(c.location + ', ' + c.country);
      // Show Temp
      $('#temp').html(c.showFahrenheit === false ? c.celcius : c.fahrenheit);
    },

    showCurrentCoverage: function() {
      var c = Weather.cache;
      var currentTime = new Date().getTime() / 1000;

      // Show Day/Night Icon based on current time
      if (currentTime > c.sunrise && currentTime < c.sunset) {
        $('#icon').attr('class', 'wi wi-owm-day-' + c.icon);
      } else {
        $('#icon').attr('class', 'wi wi-owm-night-' + c.icon);
      }
      // Show coverage text
      $('#coverage').html(Weather.cache.coverage);
    },

    showTime: function() {
      var time = new Date();
      var hours = time.getHours();
      var minutes = time.getMinutes();

      // Display a zero before hours/minutes if below 10
      if (hours < 10) {
        $('#time').html(minutes < 10 ? '0' + hours + ':0' + minutes : '0' + hours + ':' + minutes);
      } else {
        $('#time').html(minutes < 10 ? hours + ':0' + minutes : hours + ':' + minutes);
      }
    },

    changeUnit: function() {
      var c = Weather.cache;

      // Toggle temp unit type on click
      if (c.showFahrenheit === false) {
        $('#temp').html(c.fahrenheit);
        c.showFahrenheit = true;
      } else {
        $('#temp').html(c.celcius);
        c.showFahrenheit = false;
      }

      // Toggles the button knob
      $('#unit-toggle').toggleClass('toggle');
      // Creates the fade in effect on the temp text
      $('#temp').toggleClass('toggle');
    },

    refresh: function() {
      Weather.showTime();
      Weather.getLocation();
    }
  };

  Weather.init();

})();
              
            
!
999px

Console