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 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.

HTML

              
                <head>
  <title>Local Weather App</title>
  <meta charset='UTF-8'>
</head>

  <body class="weather-app">
    <div class="box-wrapper">
    <div class="nav">
      <p id="dt">{{Data.time}}</p>      
    </div>
     
     <section class="box row-city">
       <h1 id="location">{{Data.city}}</h1>
      </section>
    
    <section class="box row-temperature">
      <p class="temperature">
        <span id="temp"></span> 
        <a id="fahrenheit" class="active metric" href="#">&nbsp;&#176;F </a>
        <span style="font-size: 1.4rem;">   |</span>
        <a id="celsius" class="metric checked" href="#">&#176;C</a>
      </p>
    </section>
      
      <section class="box row-current">
        <div class="icon-wrapper">
          <i id="icon" width="40px" height="50px"></i>
        </div>
        <p class="description"></p>
      </section>
    
    <section class="box row row-details">
      <div class="col-xs-4">
        <h2>Wind</h2>
        <p class="details" id="speed"></p>
      </div>
      <div class="col-xs-4">
        <h2>Direction</h2>
        <p class="details" id="direction"></p>
      </div>
      <div class="col-xs-4">
        <h2>Humidity</h2>
        <p class="details" id="humidity"></p>
      </div>
    </section>
    </div>
         
    <footer>
      <p>by <a href="http://gphughes.com">gavin</a></p>
    </footer>
  </body>
     
              
            
!

CSS

              
                @import url('https://cdnjs.cloudflare.com/ajax/libs/weather-icons/1.3.2/css/weather-icons.min.css');

* {
  margin: 0;
  padding: 0;
  font-family: "Raleway", "New Times Roman", sans-serif;
}

html {
  width: 100vw;
  height: 100vh;
}

h2 {
  color: #ffffff;
  text-transform: uppercase;
  font-size: 1.3rem;
  margin-top: 0px;
  margin-bottom: 0px;
}

h3, p {
  font-weight: 400;
  font-size: 1.2rem;
}

a {
  text-decoration: none;
}

a:hover {
  color: blue;
}

body {
  margin: 0;
  padding: 0;
  text-align: center;
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #f2f2f2;
}

.box-wrapper {
  width: 250px;
  margin: 50px auto 0;
  box-shadow: 0 0 35px 10px rgba(79,69,66,0.2);
}

.nav {
  background-color: #ffffff;
  color: #000000;
  padding: 10px;
}

.box {
  background-color: rgba(0,48,88,0.4);
  color: #ffffff;
  border-bottom: 1px solid #bbc5cd;
  margin: 0 auto;
  padding: 10px 5px;
}

#dt {
  margin: 4px auto 0;
  font-size: 1.3rem;
  font-weight: 500;
}

#location {
  font-size: 2rem;
  font-variant: small-caps;
  margin-top: 10px;
}

.description {
  font-weight: bold;
  font-size: 14px;
}

.icon-wrapper {
  margin: 8px auto 0px;
  font-size: 4.5em;
}

.row-temperature {
  border-bottom: 1px solid #bbc5cd; 
  padding: 0 5px 10px;
}

#temp {
  font-size: 6rem;
}

.temperature {
  margin: 0;
}

.metric {
  font-size: 1.8rem;
  color: #fff;
}

.active {
  text-decoration: none;
  color: blue;
}

.metric:hover, .metric:focus {
  text-decoration: none;
  color: blue;
}

.row-details {
  margin-bottom: 10px;
  padding: 20px 0 10px;
}

.row-details h2 {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 10px;
}

.row-details p.details:hover {
  -webkit-transform: scale(1.2);
  transform: scale(1.2);
  -webkit-transition-property: background,-webkit-transform;
  transition-property: background,-webkit-transform;
  transition-property: transform,background;
  transition-property: transform,background,-webkit-transform;
  -webkit-transition-duration: .3s;
  transition-duration: .3s;
}

footer p {
  margin: 5px auto;
  font-size: 10px;
}

footer a {
  text-decoration: none;
  color: blue;
}
              
            
!

JS

              
                // if it's not working, the weather source is tweaking their API

var temp;
var tempC;
var tempF;

$(document).ready(function getPosition() {
  var location = "http://ip-api.com/json";
  
  $.getJSON(location, function(json) {
    // Store for weather API input
    var lat = json.lat;
    var lon = json.lon;
    // Pass City and State to view
    var city = json.city;
    var state = json.region;
    var cityState = city + ", " + state;
    $("#location").html(cityState);
    
    // Get the Date
    var dt = $('#dt');
    var currentDate = new Date();
    // Create array and replace month number with month name
    var month = new Array();
    month[0] = "January";
    month[1] = "February";
    month[2] = "March";
    month[3] = "April";
    month[4] = "May";
    month[5] = "June";
    month[6] = "July";
    month[7] = "August";
    month[8] = "September";
    month[9] = "October";
    month[10] = "November";
    month[11] = "December";
    
    // Convert from military time to standard
    var currentHour = currentDate.getHours();
    if(currentHour == 00) {
      currentHour = 12;
    } else if(currentHour >= 13) {
      currentHour -= 12;
    }
    // Insert leading zero if necessary
    var currentMinute = currentDate.getMinutes();
    if(currentMinute < 10) {
      currentMinute = '0' + currentMinute;
    } else {
      currentMinute;
    }
    // Determine whether it's AM or PM
    var ampm = currentDate.getHours();
    if(currentDate.getHours() >= 12) {
      ampm = 'PM';
    } else {
      ampm ='AM';
    }
    // Store full date and time  
    var dateTime = month[currentDate.getMonth()] + ' ' + currentDate.getDate() + ', ' + currentHour + ':' + currentMinute + ' ' + ampm;
    // Display date
    dt.html(dateTime);

    //Get the weather data from the open weather API
    $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=b2d3758d7d1b3c72dba58b807cebbe7e", function(json) {

      var country = json.sys.country;
      var town = json.name;
      var location = town + ", " + country;

      var weather = json.weather[0].description;
      $("#weather").html(weather);

      var tempK = json.main.temp;
      tempC = Math.round((tempK - 273.15));
      tempF = Math.round(tempC * 1.8 + 32);
      $("#temp").html(tempF);
      
      var speed = json.wind.speed;
      $('#speed').html(speed + " m/s");
      var direction = json.wind.deg;
      $('#direction').html(direction + "°");
      var humidity = json.main.humidity;
      $('#humidity').html(humidity + "%");

      // Change temp value upon change of temp unit
      $("#celsius").on("click", function() {
        $("#fahrenheit").removeClass("active");
        $("#celsius").addClass("active");
        $("#temp").html(tempC);
      });
      $("#fahrenheit").on("click", function() {
        $("#celsius").removeClass("active");
        $("#fahrenheit").addClass("active");
        $("#temp").html(tempF);
      });
      
      // Change icon depending on temperature
      var $icon = $('#icon').attr('src', '');
      $icon.removeClass();
      // Insert weather icon
      $(".description").html(weather);
      // Use switch and case to grab icons 
      switch (json.weather[0].icon) {
        case '01d':
          $icon.addClass('wi wi-day-sunny');
          break;
        case '02d':
          $icon.addClass('wi wi-day-sunny-overcast');
          break;
        case '01n':
          $icon.addClass('wi wi-night-clear');
          break;
        case '02n':
          $icon.addClass('wi wi-night-partly-cloudy');
          break;
      }

      switch (json.weather[0].icon.substr(0, 2)) {
        case '03':
          $icon.addClass('wi wi-cloud');
          break;
        case '04':
          $icon.addClass('wi wi-cloudy');
          break;
        case '09':
          $icon.addClass('wi wi-showers');
          break;
        case '10':
          $icon.addClass('wi wi-rain');
          break;
        case '11':
          $icon.addClass('wi wi-thunderstorm');
          break;
        case '13':
          $icon.addClass('wi wi-snow');
          break;
        case '50':
          $icon.addClass('wi wi-fog');
          break;
      }
    });
  });
});
  
              
            
!
999px

Console