cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="row weather-container">
  <header align="center">
    <h1 id="city">(city N/A)</h1>
    <i id="weather-icon" class="wi wi-day-sunny"></i>
    <h2 id="description">(description N/A)</h2>
  </header>

  <section align="center">
    <h1 id="temp">N/A</h1>
    
    <div class="temp-range">
      <i class="wi wi-thermometer-exterior" id="temp-range-low"> N/A</i>
      <i class="wi wi-thermometer" id="temp-range-high"> N/A</i>
    </div>
    <h3 id="humidity">Humidity N/A</h3>
    <h3 id="cloudiness">Cloudiness N/A</h3>
    <h3 id="wind-speed">Wind Speed N/A mph</h3>
  </section>
  
  <button id="switch-metrics">°C</button>
  
</div>
            
          
!
            
              html * {
  font-family: Roboto, sans-serif;
}
body {
  background-color: #4DB6AC;
}
.container-fluid,
.row {
  padding: 0;
  margin: 0;
}
.vertical-bar {
  border-right: 2px #607D8B solid;
  margin: 0 30px;
}
.weather-container {
  min-width: 800px;
}
header {
  width: 30%;
  height: 100vh;
  background-color: #4DB6AC;
  color: #E0F2F1;
}
header #city {
  font-family: Roboto, sans-serif;
  font-size: 34px;
  padding-top: 23%;
}
header #weather-icon {
  font-size: 150px;
  padding: 60px 0 35px 0;
}
header #description {
  font-family: Roboto Thin, sans-serif;
  font-size: 34px;
  padding-bottom: 15%;
  background: #4DB6AC;
}
section {
  float: right;
  width: 70%;
  padding-top: 5%;
  background-color: #E0F2F1;
  color: #607D8B;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}
section i {
  font-family: Roboto, sans-serif;
  font-size: 30px;
}
section .temp-range {
  margin-bottom: 20px;
}
section #temp {
  color: #455A64;
  font-size: 150px;
}
section #temp-range-low {
  padding-right: 35px;
}
#switch-metrics:hover {
  background-color: #607D8B;
  color: #E0F2F1;
}
#switch-metrics {
  outline: none !important;
  position: fixed;
  right: 0;
  bottom: 0;
  margin: 15px;
  width: 55px;
  height: 55px;
  font-size: 30px;
  font-family: "Roboto", sans-serif;
  color: #607D8B;
  background-color: #ECF1F0;
  border: 1px #607D8B solid;
  border-radius: 200px;
}

            
          
!
            
              //main load weather function
function loadWeather() {
  var City, State, Dir, IP, IP_Info;
  var latitude, longitude, weatherUrl2;
  var Units = 'C';
  //gets IP

  //gets location based on ip
  $.getJSON(
    'http://ipinfo.io',
    function(loc) {
      IP = loc.ip;
      IP_Info = 'http://ipinfo.io/' + IP;

      $.getJSON(
        'http://ipinfo.io/' + loc.ip,
        function(location) {
          City = location.city;
          State = location.region;
          $('.location').append('Location: ' + City + ', ').append(State);
          var weatherUrl =
            'http://api.openweathermap.org/data/2.5/weather?q=' +
            City +
            '&units=metric&APPID=b712b386a2d044d53f71ff581397682e';

          // gets conditions based on openweathermap api
          $.get(
            weatherUrl,
            function(conditions) {
              if (conditions.wind.deg >= 20 && conditions.wind.deg <= 60)
                Dir = 'NE';
              if (conditions.wind.deg >= 61 && conditions.wind.deg <= 120)
                Dir = 'E';
              if (conditions.wind.deg >= 121 && conditions.wind.deg <= 160)
                Dir = 'SE';
              if (conditions.wind.deg >= 161 && conditions.wind.deg <= 200)
                Dir = 'S';
              if (conditions.wind.deg >= 241 && conditions.wind.deg <= 285)
                Dir = 'SW';
              if (conditions.wind.deg >= 286 && conditions.wind.deg <= 340)
                Dir = 'SW';
              if (conditions.wind.deg <= 20) Dir = 'N';

              //generate icon based on API data
              $('#icon').prepend(
                '<img src="http://openweathermap.org/img/w/' +
                  conditions.weather[0].icon +
                  '.png" alt="weather icon class="img-responsive" />'
              );

              $('#temp').append(conditions.main.temp + ' ' + Units);
              $('.conditions').append(
                'Weather: ' + conditions.weather[0].description
              );
              $('.wind').append(
                'Wind:' + conditions.wind.speed + ' knots ' + Dir
              );

              $('#convertF').click(function() {
                if ((Units = 'C')) Units = 'F';
                $('#temp').text(
                  parseInt(conditions.main.temp * 9 / 5 + 32) + ' ' + Units
                );
                $('#convertC').show();
                $('#convertF').hide();
              });
              $('#convertC').click(function() {
                if ((Units = 'F'))
                  Units = 'C'('#temp').text(
                    parseInt(conditions.main.temp - 32) + ' ' + Units
                  );
                $('#convertF').css('display', 'inline');
                $('#convertC').css('display', 'none');
              });
              // change background based on weather
              switch (conditions.weather[0].main) {
                case 'Rain':
                  $('body').css(
                    'background-image',
                    'url("https://terribleeker.files.wordpress.com/2010/05/may18-2010web-6.jpg")'
                  );
                  break;
                case 'Clouds':
                  $('body').css(
                    'background-image',
                    'url("https://unsplash.it/1200/800?image=84")'
                  );
                  break;
                case 'Clear':
                  $('body').css(
                    'background-image',
                    'url("https://snap-photos.s3.amazonaws.com/img-thumbs/960w/RVO75X4E0Z.jpg")'
                  );
                  break;
                case 'Snow':
                  $('body').css(
                    'background-image',
                    'url("https://stochasticobservations.files.wordpress.com/2009/12/dsc01319.jpg")'
                  );
                  break;
                case 'Mist':
                  $('body').css(
                    'background-image',
                    'url("http://indianhomemakerphotos.files.wordpress.com/2014/02/fog-2-highway.jpg")'
                  );
                  break;
                default:
                  $('body').css(
                    'background-image',
                    'url("https://unsplash.it/1200/800?image=85")'
                  );
              }
            },
            'json'
          );
        },
        'jsonp'
      );
    },
    'jsonp'
  );
}
$(document).ready(loadWeather);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console