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="wrapper">
  <h1>Weather App</h1>
  <section class="location">
    <p data-location></p>
  </section>
  <section class="weather" data-current="celsius">
    <div class="weather-icon"></div>
    <div class="weather-temperature">
      <span class="weather-temperature-unit weather-temperature-avg" title="Average"></span>
      <span class="weather-temperature-unit weather-temperature-high" title="Max"></span>
      <span class="weather-temperature-unit weather-temperature-low" title="Min"></span>
    </div>
    <button class="switch-unit" type="button" title="Switch unit">
      <i class="fa fa-refresh"></i>
    </button>
  </section>
</div>
              
            
!

CSS

              
                // Moods
$undef = #34495e
$rainy = #1f3a93
$clear = #89c4f4
$snowy = #ececec

// Elements sizes
$size-wrapper = 300px
$size-weather-box-primary = 180px
$size-weather-box-secondary = $size-weather-box-primary / 2

// Elements
:root
  font-family 'Lato', 'Arial', sans-serif
  font-size 20px

body
  background-color $undef
  color #fff
  transition background-color 1000ms linear
  
h1, p
  text-align center
  
p
  height 1.2em
  margin 2px 0
  
button
  background none
  border none
  margin 0
  padding 0
  position absolute
  bottom 10px
  right 10px
  
// Components
  .weather-clear
    background-color $clear
    
  .wrapper
    background-color rgba(200,200,200,.4)
    border-radius 6px
    box-shadow 0.2em 0.2em 0.2em #444
    margin 10px auto
    min-height $size-wrapper
    padding 5px 25px
    position relative
    @media screen and (min-width: ($size-wrapper * 1.5))
      max-width $size-wrapper
    
  .weather-temperature
    display flex
    flex-direction column
    flex-wrap wrap
    height $size-weather-box-primary
    
  .weather-temperature-unit
    font-size 2em
    text-align center
    position relative
    line-height $size-weather-box-secondary
    height $size-weather-box-secondary
    width $size-weather-box-secondary
    &:before
      content attr(title)
      font-size .3em
      position absolute
      top -2em
    &:after
      font-size .6em
      vertical-align super

  .weather-temperature-avg
    font-size 2.5em
    line-height $size-weather-box-primary
    height $size-weather-box-primary
    width $size-weather-box-primary
    
  [data-current="celsius"] .weather-temperature-unit:after
    content '°C'
    
  [data-current="fahrenheit"] .weather-temperature-unit:after
    content '°F'
              
            
!

JS

              
                var WeatherService = (function() {
  var serviceUrl = 'http://api.wunderground.com/api/479ed091f3e5f6df';
  var forecastUrl = serviceUrl + '/forecast'
  var locationUrl = serviceUrl + '/geolookup/q/autoip.json';
  var locationCode, city;

  var fetchedLocation = (function fetchLocation() {
    return $.getJSON(locationUrl).then(function(res) {
      city = res.location.city;
      locationCode = res.location.l;
    });
  }());

  return function() {
    return {
      getWeather: function() {
        return $.when(fetchedLocation).then(function() {
          return $.getJSON(forecastUrl + locationCode + '.json');
        });
      },
      getCity: function() {
        return $.when(fetchedLocation).then(function() {
          return city;
        });
      }
    }
  }
}());

$(function() {
  function currentUnit() {
    return $(".weather").attr("data-current");
  }

  function switchToCurrentUnit() {
    var unit = currentUnit();
    $(".weather-temperature-avg, .weather-temperature-high, .weather-temperature-low").each(function() {
      $(this).text($(this).data(unit));
    });
  }

  $(".switch-unit").on("click", function() {
    var unit = currentUnit() === "celsius" ? "fahrenheit" : "celsius";
    $(".weather").attr("data-current", unit);

    switchToCurrentUnit();
  });

  WeatherService().getCity().then(function(city) {
    $("[data-location]").text(city);
  });

  WeatherService().getWeather().then(function(response) {
    var forecast = response.forecast.simpleforecast.forecastday[0];

    var high = {
      celsius: Number.parseFloat(forecast.high.celsius),
      fahrenheit: Number.parseFloat(forecast.high.fahrenheit)
    };

    var low = {
      celsius: Number.parseFloat(forecast.low.celsius),
      fahrenheit: Number.parseFloat(forecast.low.fahrenheit)
    };

    var average = {
      celsius: (high.celsius + low.celsius) / 2,
      fahrenheit: (high.fahrenheit + low.fahrenheit) / 2
    };
    
    var weatherClass = "weather-" + forecast.conditions.toLowerCase();

    $(".weather-temperature-avg").data({
      celsius: average.celsius,
      fahrenheit: average.fahrenheit
    });

    $(".weather-temperature-high").data({
      celsius: high.celsius,
      fahrenheit: high.fahrenheit
    });

    $(".weather-temperature-low").data({
      celsius: low.celsius,
      fahrenheit: low.fahrenheit
    });

    $("body").removeClass().addClass(weatherClass);
    
    switchToCurrentUnit();
  });
});
              
            
!
999px

Console