123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
              <link href="https://fonts.googleapis.com/css?family=Pacifico|Raleway" rel="stylesheet">

<body>  
  <div class="container flex">
    <div class="row">
      <div id='box' class="text-center col-lg-8 col-lg-offset-2 well">
      <div id='logoBack'class="well fade-in one">
        <h1 id='logo' class="fade-in two">Weather App</h1>
      </div>  
      
      <div id="weatherInfo" class="fade-in three"></div>
      <a id='toggleTemp' class="fade-in four btn btn-lg btn-primary">F / C</a>
      <a id='refresh' class="fade-in btn four btn-lg btn-primary">Refresh</a>
    </div>  
  </div>
</body>
            
          
!
            
              @-webkit-keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }

body {
  margin-top: 30px;
  background-color: #add8e6;
  background-image: url('https://static1.squarespace.com/static/549f2dbfe4b0d1a214ad200b/t/55a9757be4b069b20ed9f7c2/1437169020625/clouds-sky-photography-1280x800.jpg?format=1500w');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  min-width: 295px;
  transition: background linear 1.5s;
  font-family: 'Raleway', sans-serif;
}

p {
  font-size: 20px;
}

#box {
  margin-top: 50px;
  border: 2px solid black;
}

#logo {
  background-color: #add8e6;
  color: white;
  font-family: 'Pacifico', cursive;
  font-size: 50px;
  margin-bottom: 30px;
  -webkit-text-stroke-color: black;
  -webkit-text-stroke-width: 2px;
  
}

#logoBack {
  padding-top: 0px;
  padding-bottom: 0px;
  padding-left: 0px;
  padding-right: 0px;
  border: 2px solid black;
  margin-top: 10px;
  margin-left: 150px;
  margin-right: 150px;
  background-color: #add8e6;
}

.btn {
  background-color: #add8e6;
  border: 2px solid black;
  font-size: 35px;
  font-family: 'Pacifico', cursive;
  -webkit-text-stroke-color: black;
  -webkit-text-stroke-width: 2px;
  margin: 15px;
}

.btn:hover {
  background-color: #52badc;
  border: 2px solid black;
}

.btn:active {
  background-color: green;
  border: 2px solid black;
}

#obsTime {
  font-size: 15px;
}

.fade-in {
    opacity:0;  /* make things invisible upon start */
    -webkit-animation:fadeIn ease-in 1;  /* call our keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
    -moz-animation:fadeIn ease-in 1;
    animation:fadeIn ease-in 1;

    -webkit-animation-fill-mode:forwards;  /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 1)*/
    -moz-animation-fill-mode:forwards;
    animation-fill-mode:forwards;

    -webkit-animation-duration:1s;
    -moz-animation-duration:1s;
    animation-duration:1s;
}

.fade-in.one {
-webkit-animation-delay: 0.7s;
-moz-animation-delay: 0.7s;
animation-delay: 0.7s;
}

.fade-in.two {
-webkit-animation-delay: 1.2s;
-moz-animation-delay:1.2s;
animation-delay: 1.2s;
}

.fade-in.three {
-webkit-animation-delay: 1.6s;
-moz-animation-delay: 1.6s;
animation-delay: 1.6s;
}

.fade-in.four {
-webkit-animation-delay: 2.1s;
-moz-animation-delay: 2.1s;
animation-delay: 2.1s;
}

            
          
!
            
              /*
- make a background updater function
- add animations fade in and fade out 
*/

function showWeather(data) {
  var city = data.current_observation.display_location.city,
      state = data.current_observation.display_location.state,
      url = data.current_observation.image.url,
      temp_f = data.current_observation.temp_f,
      temp_c = data.current_observation.temp_c,
      feelslike_f = data.current_observation.feelslike_f,
      feelslike_c = data.current_observation.feelslike_c,
      observation_time = data.current_observation.observation_time,
      weather = data.current_observation.weather,
      icon = data.current_observation.icon,
      icon_url = data.current_observation.icon_url;
  $('#weatherInfo').html(
    '<p id="location">' + city + ', ' + state + '</p>' +
    '<img id="icon" src=' + icon_url + '>' +
    '<p id="weather" class="Information">' + weather + '</p>' +
    '<p id="tempInF" class="Farenheit Information">' + temp_f + ' &degF</p>' +
    '<p id="feelsLikeF" class="Farenheit Information">Feels like ' + feelslike_f + '  &degF</p>' +
    '<p id="tempInC" class="Celsius Information">' + temp_c + ' &degC</p>' +
    '<p id="feelsLikeC" class="Celsius Information">Feels like ' + feelslike_c + ' &degC</p>' +
    '<p id="obsTime" class="Information">' + observation_time + '</p>'
  );
  $('.Celsius').hide();
}

function getPicture(data) {
  var weatherString = data.current_observation.weather;
  console.log(weatherString);
  var weatherArray = weatherString.split(" ");
  console.log(weatherArray);
  var HeavyOrLight = weatherArray[0];
  console.log(HeavyOrLight);
  var remainderArray = weatherArray.slice(1);
  console.log(remainderArray);
  var remainderString = remainderArray.join(' ');
  console.log(remainderString);
  if (HeavyOrLight === 'Light' || HeavyOrLight === 'Heavy') {
    for (i=0; i < remainderArray.length; i++) {
      switch(remainderArray[i]) {
        // --- RAIN CASES ---
        case 'Drizzle':
        case 'Rain':
        case 'Thunderstorm':
        case 'Thunderstorms':
          $('body').css('background-image', "url('https://psuchronicles.files.wordpress.com/2013/10/outdoor_raining-1280x800.jpg')");
          break;
          
        // --- SNOW / ICE CASES ---
        case 'Snow':
        case 'Ice':
        case 'Hail':
          $('body').css('background-image', "url('https://s-media-cache-ak0.pinimg.com/originals/f8/92/1a/f8921a12753b1f92f199cb0d495a3421.jpg')");
          break;
        
        // --- MIST ---
        case 'Mist':
        case 'Fog':
          $('body').css('background-image', "url('http://wallpapersonthe.net/wallpapers/b/1280x800/1280x800-mist_hill_nature_landscape-3900.jpg')");
          break;
          
        // --- VOLCANIC ASH ---
        case 'Ash':
          $('body').css('background-image', "url('http://www.jpl.nasa.gov/spaceimages/images/wallpaper/PIA20371-1280x800.jpg')");
          break;
          
        // --- DUST ---
        case 'Dust':
        case 'Sand':
        case 'Sandstorm':
          $('body').css('background-image', "url('http://www.danielhaydenberman.com/wp-content/images/Wallpaper%20Wednesday/Week%209/La%20Grande%20storm%201280x800.jpg')");
          break; 
          
                              } //end switch statement 
    } //end for loop 
    
    } else {
      for (i=0; i < weatherArray.length; i++) {
        switch(weatherArray[i]) {
          // --- CLOUD / CLOUDY ---
          case 'Clouds':
          case 'Cloudy':
          case 'Cloud':
            $('body').css('background-image',"url('http://www.bestwallpapershq.com/wp-content/uploads/2016/04/cloudy_mountains_4k_5k-HD-1280x800.jpg')");
            break;
          
          // --- CLEAR ---
          case 'Clear':
            $('body').css('background-image',"url('https://static1.squarespace.com/static/549f2dbfe4b0d1a214ad200b/t/55a9757be4b069b20ed9f7c2/1437169020625/clouds-sky-photography-1280x800.jpg?format=1500w')");
            break;
          
          // --- OVERCAST ---
          case 'Overcast':
            $('body').css('background-image',"url('https://hqwallbase.site/images/big/cliff_nature_clouds_mountain_forest_grass_trees_hdr_water_pine_trees_landscape_overcast_river-190700.jpg')");
            break;
            
          // --- SQUALLS ---
          case 'Squalls':
            $('body').css('background-image',"url('https://unsplash.com/search/storm?photo=7e_gFC2Ce04/1600x900')");
            break;
            
          // --- UNKNOWN ---
          case 'Unknown':
            $('body').css('background-image',"url('https://unsplash.com/photos/jwfk2hlg7t4/1600x900')");
            break;
            
        } //end switch statement
      } //end for loop
    } //end else statement
} //end function

function getWeatherAndPicture () {
  $.getJSON('https://api.wunderground.com/api/32057b04a951d90e/conditions/q/autoip.json', function(data) {
    console.log(data);
    showWeather(data);
    getPicture(data);
  });
}
  
$(document).ready(function() {
  getWeatherAndPicture();
  $('#refresh').click(getWeatherAndPicture());
  $('#toggleTemp').click(function() {
    $('.Farenheit').toggle("slow");
    $('.Celsius').toggle("slow");
  });  
});  



            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console