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="loading">
    <div class="spinner">
        <div class="mask">
            <div class="maskedCircle"></div>
        </div>
    </div>
</div>
<div class="container">
  <h1>Local Weather</h1>
  <h2>For <span class="city"></span></h2>
  <div class="row">
    <div class="col-xs-4 col-xs-offset-2 col-sm-4 col-sm-offset-2 col-md-3 col-md-offset-3 col-lg-2 col-lg-offset-4">
      <h3 class="weather"></h3>
      <h3><span class="temp"></span><span class="metric"></span></h3>
      <h3 class="wind"><span class="speed"></span> MPH - <span class="direction"></span></h3>
    </div>
    <div class="col-xs-4 col-sm-4 col-md-2">
      <div class="weather-icon"></div>
    </div>
  </div>
  <div class="row">
    <div class="col-xs-4 col-xs-offset-2 col-sm-4 col-sm-offset-2 col-md-3 col-md-offset-3 col-lg-4 col-lg-offset-4">
      <button id="conversion" class="f">Convert to Celcius</button>
    </div>
  </div>
  
</div>
              
            
!

CSS

              
                body {
  background-color:#000;
  color:#000;
}
.container {
  display: none;
}
.weather {
  text-transform: capitalize;
}

h1, h2, h3 {
  color:#FFF;
}

h1, h2 {
  text-align: center;
}

button {
  display:block;
  background:transparent;
  color:white;
  border: 3px solid;
  margin:1em 0 0 0 ;
  
  &:focus {
    outline:none;
  }
}

.f {
  border-color:#00BFFF;
}

.c {
  border-color:red;
}

// Josh Bader's Animated Weather Icons

.icon {
  position: relative;
  display: inline-block;
  width: 12em;
  height: 10em;
  font-size: 1em; /* control icon size here */
}

.cloud {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 3.6875em;
  height: 3.6875em;
  margin: -1.84375em;
  background: currentColor;
  border-radius: 50%;
  box-shadow:
    -2.1875em 0.6875em 0 -0.6875em,
    2.0625em 0.9375em 0 -0.9375em,
    0 0 0 0.375em #fff,
    -2.1875em 0.6875em 0 -0.3125em #fff,
    2.0625em 0.9375em 0 -0.5625em #fff;
}
.cloud:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -0.5em;
  display: block;
  width: 4.5625em;
  height: 1em;
  background: currentColor;
  box-shadow: 0 0.4375em 0 -0.0625em #fff;
}
.cloud:nth-child(2) {
  z-index: 0;
  background: #fff;
  box-shadow:
    -2.1875em 0.6875em 0 -0.6875em #fff,
    2.0625em 0.9375em 0 -0.9375em #fff,
    0 0 0 0.375em #fff,
    -2.1875em 0.6875em 0 -0.3125em #fff,
    2.0625em 0.9375em 0 -0.5625em #fff;
  opacity: 0.3;
  transform: scale(0.5) translate(6em, -3em);
  animation: cloud 4s linear infinite;
}
.cloud:nth-child(2):after { background: #fff; }

.sun {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.5em;
  height: 2.5em;
  margin: -1.25em;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 0.375em #fff;
  animation: spin 12s infinite linear;
}
.rays {
  position: absolute;
  top: -2em;
  left: 50%;
  display: block;
  width: 0.375em;
  height: 1.125em;
  margin-left: -0.1875em;
  background: #fff;
  border-radius: 0.25em;
  box-shadow: 0 5.375em #fff;
}
.rays:before,
.rays:after {
  content: '';
  position: absolute;
  top: 0em;
  left: 0em;
  display: block;
  width: 0.375em;
  height: 1.125em;
  transform: rotate(60deg);
  transform-origin: 50% 3.25em;
  background: #fff;
  border-radius: 0.25em;
  box-shadow: 0 5.375em #fff;
}
.rays:before {
  transform: rotate(120deg);
}
.cloud + .sun {
  margin: -2em 1em;
}

.rain,
.lightning,
.snow {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 3.75em;
  height: 3.75em;
  margin: 0.375em 0 0 -2em;
  background: currentColor;
}

.rain:after {
  content: '';
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 1.125em;
  height: 1.125em;
  margin: -1em 0 0 -0.25em;
  background: #0cf;
  border-radius: 100% 0 60% 50% / 60% 0 100% 50%;
  box-shadow:
    0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
    -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
    -1.375em -0.125em 0 rgba(255,255,255,0.2);
  transform: rotate(-28deg);
  animation: rain 3s linear infinite;
}

.bolt {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -0.25em 0 0 -0.125em;
  color: #fff;
  opacity: 0.3;
  animation: lightning 2s linear infinite;
}
.bolt:nth-child(2) {
  width: 0.5em;
  height: 0.25em;
  margin: -1.75em 0 0 -1.875em;
  transform: translate(2.5em, 2.25em);
  opacity: 0.2;
  animation: lightning 1.5s linear infinite;
}
.bolt:before,
.bolt:after {
  content: '';
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  margin: -1.625em 0 0 -1.0125em;
  border-top: 1.25em solid transparent;
  border-right: 0.75em solid;
  border-bottom: 0.75em solid;
  border-left: 0.5em solid transparent;
  transform: skewX(-10deg);
}
.bolt:after {
  margin: -0.25em 0 0 -0.25em;
  border-top: 0.75em solid;
  border-right: 0.5em solid transparent;
  border-bottom: 1.25em solid transparent;
  border-left: 0.75em solid;
  transform: skewX(-10deg);
}
.bolt:nth-child(2):before {
  margin: -0.75em 0 0 -0.5em;
  border-top: 0.625em solid transparent;
  border-right: 0.375em solid;
  border-bottom: 0.375em solid;
  border-left: 0.25em solid transparent;
}
.bolt:nth-child(2):after {
  margin: -0.125em 0 0 -0.125em;
  border-top: 0.375em solid;
  border-right: 0.25em solid transparent;
  border-bottom: 0.625em solid transparent;
  border-left: 0.375em solid;
}

.flake:before,
.flake:after {
  content: '\2744';
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -1.025em 0 0 -1.0125em;
  color: #fff;
  list-height: 1em;
  opacity: 0.2;
  animation: spin 8s linear infinite reverse;
}
.flake:after {
  margin: 0.125em 0 0 -1em;
  font-size: 1.5em;
  opacity: 0.4;
  animation: spin 14s linear infinite;
}
.flake:nth-child(2):before {
  margin: -0.5em 0 0 0.25em;
  font-size: 1.25em;
  opacity: 0.2;
  animation: spin 10s linear infinite;
}
.flake:nth-child(2):after {
  margin: 0.375em 0 0 0.125em;
  font-size: 2em;
  opacity: 0.4;
  animation: spin 16s linear infinite reverse;
}


/* Animations */ 

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

@keyframes cloud {
  0% { opacity: 0; }
  50% { opacity: 0.3; }
  100% {
    opacity: 0;
    transform: scale(0.5) translate(-200%, -3em);
  }
}

@keyframes rain {
  0% {
    background: #0cf;
    box-shadow:
      0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
      -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
      -1.375em -0.125em 0 #0cf;
  }
  25% {
    box-shadow:
      0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
      -0.875em 1.125em 0 -0.125em #0cf,
      -1.375em -0.125em 0 rgba(255,255,255,0.2);
  }
  50% {
    background: rgba(255,255,255,0.3);
    box-shadow:
      0.625em 0.875em 0 -0.125em #0cf,
      -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
      -1.375em -0.125em 0 rgba(255,255,255,0.2);
  }
  100% {
    box-shadow:
      0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
      -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
      -1.375em -0.125em 0 #0cf;
  }
}

@keyframes lightning {
  45% {
    color: #fff;
    background: #fff;
    opacity: 0.2;
  }
  50% {
    color: #0cf;
    background: #0cf;
    opacity: 1;
  }
  55% {
    color: #fff;
    background: #fff;
    opacity: 0.2;
  }
}

/* Animation keyframes - you need to add prefixes */
@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}

@-moz-keyframes spin {
    from { -moz-transform: rotate(0deg); }
    to { -moz-transform: rotate(360deg); }
}

@-ms-keyframes spin {
    from { -ms-transform: rotate(0deg); }
    to { -ms-transform: rotate(360deg); }
}

.loading {
position: absolute;
top: 50%;
left: 50%;
width: 28px;
height: 28px;
margin: -14px 0 0 -14px;
}

.loading .spinner {
position: absolute;
left: 1px;
top: 1px;
width: 26px;
height: 26px;
-webkit-animation: spin 1s infinite linear;
-moz-animation: spin 1s infinite linear;
-o-animation: spin 1s infinite linear;
animation: spin 1s infinite linear;
}

.loading .mask {
width: 12px;
height: 12px;
overflow: hidden;
}

.loading .maskedCircle {
width: 20px;
height: 20px;
border-radius: 12px;
border: 3px solid #666;
}
              
            
!

JS

              
                function getWeather(latlon) {
  var dfrd1 = $.Deferred();
  $.getJSON('http://api.openweathermap.org/data/2.5/weather?lat='+latlon[0]+'&lon='+latlon[1]+'&appid=dfb12822ed9abac7425befb54ae3c069&units=imperial',
    function(response){
      $(".weather").html(response.weather[0].description);
      $(".temp").html(Math.round(response.main.temp));
      $(".metric").html(" F");
      $(".speed").html(response.wind.speed);
      $(".direction").html(windDirection(response.wind.deg));
      getWeatherIcon(response.weather[0].id);
      dfrd1.resolve();
    });
  return $.when(dfrd1).done().promise();
}
function getWeatherIcon(id){
  if(id > 200 && id < 232){
    $(".weather-icon").html('<div class="icon thunder-storm"><div class="cloud"></div><div class="lightning"><div class="bolt"></div><div class="bolt"></div></div></div>');
  } else if (id >= 300 && id < 532) {
    $(".weather-icon").html('<div class="icon rainy"><div class="cloud"></div><div class="rain"></div></div>');
  } else if (id > 600 && id < 623) {
    $(".weather-icon").html('<div class="icon flurries"><div class="cloud"></div><div class="snow"><div class="flake"></div><div class="flake"></div></div></div>');
  } else if (id > 700 && id < 782) {
    $(".weather-icon").html('<div class="icon cloudy"><div class="cloud"></div><div class="cloud"></div></div>');
  } else if (id == 800) {
    $(".weather-icon").html('<div class="icon sunny"><div class="sun"><div class="rays"></div></div></div>')
  } else if (id > 800 && id < 805) {
    $(".weather-icon").html('<div class="icon cloudy"><div class="cloud"></div><div class="cloud"></div></div>');
  }
}
function getLocation(latlon){
  var dfrd1 = $.Deferred();
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
      function(position){
        latlon[0] = position.coords.latitude;
        latlon[1] = position.coords.longitude;
        $(".latitude").html(latlon[0]);
        $(".longitude").html(latlon[1]);
        dfrd1.resolve();
      }
    );
  }
  return $.when(dfrd1).done().promise();
}
function getCityName(latlon){
  dfrd1 = $.Deferred();
  $.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng='+latlon[0]+','+latlon[1]+'&key=AIzaSyDxuTyuMDo_D0SH3mDWz7Z13eb-xoZl_Pk', function(response){
    $(".city").html(response.results[3]["formatted_address"]);
    dfrd1.resolve();
  });
  return $.when(dfrd1).done();
  
}
function windDirection(num){
  if(num > 0 && num <= 22.5){
    return "N";
  } else if (num > 22.5 && num <= 67.5){
    return "NE";
  } else if (num > 67.5 && num <= 112.5){
    return "E";
  } else if (num > 112.5 && num <= 157.5){
    return "SE";
  } else if (num > 157.5 && num <= 202.5){
    return "S";
  } else if (num > 202.5 && num <= 247.5){
    return "SW";
  } else if (num > 247.5 && num <= 292.5){
    return "W";
  } else if (num > 292.5 && num <= 337.5){
    return "NW";
  } else if (num > 337.5 && num <= 360){
    return "N";
  }
}
function fahrenheitToCelsius(num){
  return Math.round((num - 32) * (5/9));
}
function celsiusToFahrenheit(num){
  return Math.round((num * (9 / 5)) + 32);
}

$(document).ready(function() {
  var locationData = [];
  $(function(){
    getLocation(locationData).done(function(){
      //location done, move on to city
      getCityName(locationData).done(function(){
        //city name done, move on to weather
        getWeather(locationData).done(function(){
          //weather data complete
          $(".loading").fadeOut();
          $(".container").fadeIn();
        });
      });
    });
  });
  $('#conversion').on("click", function() {
    var currentClass = this.className;
    var currentTemp = $(".temp").html();
    if(currentClass == 'f'){
      $(".temp").html(fahrenheitToCelsius(currentTemp));
      $(".metric").html(" C");
      this.className = 'c';
      $("#conversion").html("Convert to Fahrenheit");
    } else if (currentClass == 'c'){
      $(".temp").html(celsiusToFahrenheit(currentTemp));
      $(".metric").html(" F");
      this.className = 'f';
      $("#conversion").html("Convert to Celsius");
    }
  });
});
              
            
!
999px

Console