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

              
                <h1>Weather <b>Balloons</b></h1>
<h2 id="location"></h2>
<img id="icon"/>
<div id="infoF"></div>
<div id="infoC"></div>
<button type="button" id="unitSwitch">F/C</button>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Courgette');

html {
  position: relative;
  margin: none;
  padding-top: 3%;
  height: 100vh;
  text-align: center;
  background: #bdc3c7;
  background-size: cover;
  opacity: 0;
  transition: opacity 1s ease-out;
}

h1 {
  font-family: 'Courgette', cursive;
  font-size: 100px;
  width: auto;
  color: #3498db;
  text-align: center;
  background: rgba(0,0,0,.5);
  width: 50%;
  margin: 4% auto;
  border-radius: 15px;
}

b {
  color: #bdc3c7;
  font-weight: Bold;
  font-size: 100px;
}

#location {
  color: white;
  text-align: center;
  background-color: #f39c12;
  border-radius: 11px;
  margin: 1% auto;
  min-width: 150px;
  width: 20%;
  padding: 1% 0;
  -webkit-box-shadow: inset 0px 0px 3px 2px rgba(60,100,60,1);
  -moz-box-shadow: inset 0px 0px 3px 2px rgba(60,100,60,1);
  box-shadow: inset 0px 0px 3px 2px rgba(60,100,60,1);
}

#icon {
  text-align: center;
}

#infoF {
  font-size: 20px;
  color: white;
  font-weight: bold;
  background-color: #34495e;
  text-align: center;
  padding: 1% 0;
  width: 20%;
  min-width: 150px;
  margin: 10px auto;
  border-radius: 10px;
  -webkit-box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
  -moz-box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
  box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
}

#infoC {
  font-size: 20px;
  color: white;
  font-weight: bold;
  background-color: #34495e;
  text-align: center;
  padding: 1% 0;
  width: 20%;
  min-width: 150px;
  margin: 10px auto;
  border-radius: 10px;
  -webkit-box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
  -moz-box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
  box-shadow: inset 0px 0px 6px 5px rgba(150,177,179,.6);
}

button {
  padding: 5px;
  color: black;
  font-weight: bold;
  background-color: #f39c12;
  border-radius: 5px;
  border: none;
  outline: none;
  -webkit-box-shadow: inset 0px 0px 1px 1px rgba(60,100,60,1);
  -moz-box-shadow: inset 0px 0px 1px 1px rgba(60,100,60,1);
  box-shadow: inset 0px 0px 1px 1px rgba(60,100,60,1);
}

.rain {
  background: url("https://dl.dropbox.com/s/5ocvvgpy2q2i9tz/rain.jpeg?dl=0");
  background-size: 100%;
  opacity: 1;
}

.cloudy {
  background: url("https://dl.dropbox.com/s/hkzor42mj0d28sj/overcast.jpg?dl=0");
  background-size: 100%;
  opacity: 1;
}

.storms {
  background: url("https://dl.dropbox.com/s/cft564z1zw3e5ea/stormy.jpg?dl=0");
  background-size: 100%;
  opacity: 1;
}

.fog {
  background: url("https://dl.dropbox.com/s/ubbcelefkk9bllt/mist.jpg?dl=0");
  background-size: 100%;
  opacity: 1;
}

.clear {
  background: url("https://dl.dropbox.com/s/5sf8ldp9zppa1bn/pexels-photo.jpg?dl=0");
  background-size: 100%;
  opacity: 1;
}
              
            
!

JS

              
                //I get a limited number of API calls per minute and per day so if it isn't working then I'm over the limit.
var getWeather = function() {
  var city, state, conditions, degreesF, degreesC, feelsLikeF, feelsLikeC, icon_url, clickFlag; 
  
  //Hide the Celsius info div immediately
  $('#infoC').css({'display':'none'});
  
  //Original API call to get the user's City and State using the geolookup feature.
  //Note** I believe this depends on the user's IP Adress so data could be wrong for 
  //users with a non-local IP. Also will only work for U.S. users as of now.
  var obj = $.getJSON("http://api.wunderground.com/api/8033b0b219b6db82/geolookup/q/autoip.json", function(responseText) {
    console.log(responseText);
    city = responseText.location.city;
    state = responseText.location.state;
    
    document.getElementById('location').innerHTML = city + ", " + state;
    city = city.replace(/ /g, "_");
    
    //Another API call inside the first callback function to use the city and state 
    //to get the conditions in the user's local area
    var allWeatherInfo = $.getJSON("http://api.wunderground.com/api/8033b0b219b6db82/conditions/q/" + state + "/" + city + ".json", function (responseText) {
      //Get current conditions and set background image based on conditions
      conditions = responseText.current_observation.weather;
      console.log(conditions);
      var img = new Image();
      switch(conditions) {
        case 'Light Drizzle':
        case 'Heavy Drizzle':
        case 'Light Rain':
        case 'Light Rain Mist':
        case 'Heavy Rain':
        case 'Heavy Rain Mist':
        case 'Light Rain Showers':
        case 'Heavy Rain Showers':
        img.onload = function () {
          $('html').addClass('rain', 500);
        }
        img.src = 'https://dl.dropbox.com/s/5ocvvgpy2q2i9tz/rain.jpeg?dl=0';
        break;
        case 'Overcast':
        case 'Mostly Cloudy':
          img.onload = function () {
            $('html').addClass('cloudy', 600);
          };
          img.src = 'https://dl.dropbox.com/s/hkzor42mj0d28sj/overcast.jpg?dl=0';
          break;
        case 'Light Thunderstorm':
        case 'Heavy Thunderstorm':
        case 'Light Thunderstorms and Rain':
        case 'Heavy Thunderstorms and Rain':
        case 'Light Thunderstorms and Snow':
        case 'Heavy Thunderstorms and Snow':
        case 'Light Thunderstorms and Ice Pellets':
        case 'Heavy Thunderstorms and Ice Pellets':
        case 'Light Thunderstorms with Hail':
        case 'Heavy Thunderstorms with Hail':
        case 'Light Thunderstorms with Small Hail':
        case 'Heavy Thunderstorms with Small Hail':   
        img.onload = function () {
            $('html').addClass('storms', 600);
          };
        img.src = 'https://dl.dropbox.com/s/cft564z1zw3e5ea/stormy.jpg?dl=0';
        break;
        case 'Light Mist':
        case 'Heavy Mist':
        case 'Light Fog':
        case 'Heavy Fog':
        case 'Light Freezing Fog':
        case 'Heavy Freezing Fog':
        case 'Light Fog Patches':
        case 'Heavy Fog Patches':
        case 'Partial Fog':
        case 'Patches of Fog':
        case 'Shallow Fog':
        img.onload = function () {
            $('html').addClass('fog', 600);
          };
        img.src = 'https://dl.dropbox.com/s/ubbcelefkk9bllt/mist.jpg?dl=0';
        break;
        case 'Clear':
          img.onload = function () {
            $('html').addClass('clear', 600);
          };
          img.src = 'https://dl.dropbox.com/s/5sf8ldp9zppa1bn/pexels-photo.jpg?dl=0';
      }
      
      //Store the retrieved data from the API calls in variables
      degreesF = responseText.current_observation.temp_f + "&deg F";
      feelsLikeF = "Feels like: " + responseText.current_observation.feelslike_f + "&deg F";
      degreesC = responseText.current_observation.temp_c + "&deg C";
      feelsLikeC = "Feels like: " + responseText.current_observation.feelslike_c + "&deg C";
      icon_url = responseText.current_observation.icon_url;
      
      $('#icon').attr('src', icon_url);
      
      //Populate the correct elements with the weather data
      document.getElementById('infoF').innerHTML = conditions + "<br> " + degreesF + "<br>" + feelsLikeF;
      document.getElementById('infoC').innerHTML = conditions + "<br> " + degreesC + "<br>" + feelsLikeC;
    });
  });
};

document.onload = getWeather();


//Code for the button to switch between Fahrenheit and Celsius
$('#unitSwitch').click(function() {
  if($('#infoC').css('display') =='none') {
    $('#infoC').css({'display':''});
    $('#infoF').css({'display':'none'});
  } else {
    $('#infoC').css({'display':'none'});
    $('#infoF').css({'display':''});    
  }
});


/*More possible Weather Conditions
[Light/Heavy] Snow
[Light/Heavy] Snow Grains
[Light/Heavy] Low Drifting Snow
[Light/Heavy] Ice Crystals
[Light/Heavy] Ice Pellets
[Light/Heavy] Hail
[Light/Heavy] Mist


[Light/Heavy] Smoke
[Light/Heavy] Volcanic Ash
[Light/Heavy] Widespread Dust
[Light/Heavy] Sand
[Light/Heavy] Haze
[Light/Heavy] Spray
[Light/Heavy] Dust Whirls
[Light/Heavy] Sandstorm
[Light/Heavy] Low Drifting Widespread Dust
[Light/Heavy] Low Drifting Sand
[Light/Heavy] Blowing Snow
[Light/Heavy] Blowing Widespread Dust
[Light/Heavy] Blowing Sand


[Light/Heavy] Snow Showers
[Light/Heavy] Snow Blowing Snow Mist
[Light/Heavy] Ice Pellet Showers
[Light/Heavy] Hail Showers
[Light/Heavy] Small Hail Showers

[Light/Heavy] Freezing Drizzle
[Light/Heavy] Freezing Rain
[Light/Heavy] Freezing Fog

Small Hail
Squalls
Funnel Cloud
Unknown Precipitation
Unknown*/
              
            
!
999px

Console