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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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-fluid">
  <div class="container">
    <div class="row">
      <div class="col-md-2"></div>
      <div class="col-md-8 text-center">
        <div class="bg">
          <h1>Local Weather App</h1>
          <hr>
          <div class="row">
            <div class="col-xs-6">
              <p id="coords" class="text-left">This app only works in HTTP, not HTTPS.</p>
            </div>
            <div class="col-xs-6">
              <p id="location" class="text-right">Please allow us to access your location.</p>
            </div>
          </div>
          <div class="row">
            <span id="icon">
              <div class="icon thunder-storm">
                <div class="cloud"></div>
                <div class="lightning">
                  <div class="bolt"></div>
                  <div class="bolt"></div>
                </div>
              </div>

              <div class="icon cloudy">
                <div class="cloud"></div>
                <div class="cloud"></div>
              </div>

              <div class="icon flurries">
                <div class="cloud"></div>
                <div class="snow">
                  <div class="flake"></div>
                  <div class="flake"></div>
                </div>
              </div>

              <div class="icon sunny">
                <div class="sun">
                  <div class="rays"></div>
                </div>
              </div>

              <div class="icon rainy">
                <div class="cloud"></div>
                <div class="rain"></div>
              </div>
            </span><br>
            <span id="desc"></span><br>
            Temperature: <span id="temp"></span><span id="measure"></span>
          </div>
          <button class="btn" id="convert">Convert Unit</button>
        </div>
      </div>
      <div class="col-md-2"></div>
    </div>
    <div class="row">
      <div class="row">
      <div class="col-xs-2"></div>
      <div class="col-xs-4 text-center">
        <p class="text-left footer">Icons by <a href="https://codepen.io/joshbader/pen/EjXgqr" target="_blank">Josh Bader</a></p>
      </div>
      <div class="col-xs-4 text-center">
        <p class="text-right footer">App by <a href="https://codepen.io/Nachlawi" target="_blank">David</a></p>
      </div>
      <div class="col-xs-2"></div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:600,800,800italic);

body {
  background: radial-gradient(at top, #cd32cd, #290a29) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
}

.bg {
  margin-top: 10%;
  background-color: #290a29;
  border-radius: 5px;
}
h1 {
  font-weight:800;
  font-style: italic;
  font-size: 50px;
}

div {
  color: #cd32cd;
}

hr {
  border-color: inherit;
  margin-top: 0;
}

#coords,
#location {
  padding: 10px;
}

.btn {
  margin: 10px;
  color: #290a29;
  font-weight: 800;
  background: #cd32cd;
}

.btn:hover {
  background: #d246d2;
}

.footer {
  color: lightgrey;
}

.footer a:link{
  color: #32CD32;
  font-weight: 600;
}
.footer a:visited { 
  color: #32CD32; 
  font-weight: 600;
}
.footer a:hover {
  color: #32CD32;
  font-weight: 800;
  text-decoration: none;
}

/* ANIMATED WEATHER ICONS by Josh Bader */

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

.cloud {
  color: #290a29;
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 3.6875em;
  height: 3.6875em;
  margin: -1.84375em;
  background: #290a29;
  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: #290a29;
  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: #290a29;
  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: #290a29;
}

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

JS

              
                $('.icon').hide();

var unit = 'metric';
getLocation(unit);
function getLocation(unit) {
  $.getJSON('http://ip-api.com/json/?callback=?', function(data) {
    var lat = data.lat;
    var lon = data.lon;
    $('#coords').html("Coordinates:<br>Latitude: "+lat+"<br>Longitude: "+lon);
    $('#location').html("Location:<br>"+data.city+", "+data.country+"<br>("+data.countryCode+")");
    getWeather(lat, lon, unit);
  });
}

function getWeather(lat, lon, unit) {
  $.getJSON("//api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&units="+ unit+"&APPID=cb4f69f12ef88992a22dadc1f99c4512", function(json) {
    
    // Add Celcius or Fahrenheit 
    var append;
    if (unit == "metric"){
      append = "°C";
    } else {
      append = "°F";
    }
    
    //Get description and make first letter capitlaised.
    $('#temp').html(json.main.temp+append);
    var desc = json.weather[0].description;
    desc = desc.replace(desc[0], function(letter) {
      return letter.toUpperCase();
    });
    $('#desc').html(desc);
    
    //Change the weather icon
    weather(json.weather[0].main);
    });
}; 

function weather(type){
  switch (type){
      case 'Thunderstom':
        $('.thunder-storm').show();
      break;
      case 'Drizzle':
        $('.rainy').show();
      break;
      case 'Clouds':
        $('.cloudy').show();
      break;
      case 'Snow':
        $('.flurries').show();
      break;
      case 'Clear':
        $('.sunny').show();
      break;
      case 'Rain':
        $('.rainy').show();
      break;
  }
}

$('#convert').click(function(){
  if (unit == 'metric'){
    unit = 'imperial';
  } else {
    unit = 'metric';
  }
  getLocation(unit);
});
              
            
!
999px

Console