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.

            
              <body>

  <link href='https://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
  
<!-- main banner -->  
<div class = "row">
</div>
<div class = "wrapper">
  <div class="center-block">
    <h2 class="text-center" id="city"></h2>
    <h4 class="text-center"><img id="icon" src="">
      <span id="tempF"></span> / <span id="tempC"></span></h4>

    <!--display humidity and wind speed -->
    <div class="row">
      <div class="col-xs-4"></div>
      <div class="col-xs-4 text-center">
        <h3 id="description"></h3>
        <span class="humidity">humidity:
          <span id="humidity"></span></span>
        <span class="wind-speed">wind:</span>
        <span id="wind-speed"></span>
        <span id="wind-direction"></span></span>
        </p>
      </div>
      <div class="col-xs-4">
      </div>
    </div>
 
<!-- buttons to allow user to see all background images -->
  </div>
     <p class = "text-center">
      <i class = "fa fa-sun-o fa-2x" id = "sun"></i>
      <i class = "fa fa-moon-o fa-2x" id = "moon"></i>
      <i class = "fa fa-arrow-up fa-2x" id = "up"></i>
      <i class = "fa fa-arrow-down fa-2x" id = "down"></i>
      <i class = "fa fa-umbrella fa-2x" id = "rain"></i>
      <i class = "fa fa-globe fa-2x" id = "earth"></i>
     </p>
</body>
            
          
!
            
              body { 
  background-image: "" + no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://media02.hongkiat.com/oversized-background-image-design/bg.jpg', sizingMethod='scale')";
  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.http://media02.hongkiat.com/oversized-background-image-design/bg.jpg', sizingMethod='scale');
}

.center-block{
  background-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.5);
  font-family: 'Poiret One',sans;
}

h4{
  margin-top:0;
  margin-bottom:0;
}

#icon{
  margin-left: -2%;
}

#description {
  margin-top: 0;
}

.wind-speed {
  margin-left: 10%;
}

p {
  margin-bottom: 0;
}

i {
  color: white;
  opacity: .5;
  margin-left: 1%;
  margin-right: 1%;
  margin-top: 1%;
  cursor: pointer;
}
            
          
!
            
                var city = $("#city");
  var icon = $("#icon");
  var tempF = $("#tempF");
  var tempC = $("#tempC")
  var desc = $("#description");
  var hum = $("#humidity");
  var wind = $("#wind-speed");
  var windDir = $("#wind-direction"); 



//change background based on time of day / weather code / temp
          function changeBackground(timeOfDay, weatherCode, tempF){
            
            if ((timeOfDay >= 9 && timeOfDay < 18) && (weatherCode >= 300 && weatherCode < 600)){
                $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_a09cdf37f7e44243a8c358d2873875ee.jpg/v1/fill/w_851,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_a09cdf37f7e44243a8c358d2873875ee.jpg')");
            }
            else if ((timeOfDay >= 9 && timeOfDay < 18) && (tempF > 75)){
                $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_717acf3d8dd6445a9f3f361b962cddba.jpg/v1/fill/w_946,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_717acf3d8dd6445a9f3f361b962cddba.jpg')");
            }
            else if ((timeOfDay >= 18) && (weatherCode >= 300 && weatherCode < 600)){
                $("body").css("background-image","url('http://www.paulickreport.com/wp-content/uploads/2013/02/rain-wallpaper.jpg')");
            }
            else if (timeOfDay >= 9 && timeOfDay <18){
                $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_fc7f65810de44421989ea991df501568.jpg/v1/fill/w_801,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_fc7f65810de44421989ea991df501568.jpg')");
            }
            else if (timeOfDay >= 18 && timeOfDay < 20){
              $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_36236b142a624c08bd239cea895f4916.jpg/v1/fill/w_851,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_36236b142a624c08bd239cea895f4916.jpg')");
            }
            else if (timeOfDay > 20 || timeOfDay < 5){
              $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_6f792a0ee777477a90ab8a3a75e0f0f1.jpg/v1/fill/w_945,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_6f792a0ee777477a90ab8a3a75e0f0f1.jpg')");
            }
            else if (timeOfDay >= 5 && timeOfDay < 9){
              $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_cd051484a6b6484c878dc0f7fc055c78.jpg/v1/fill/w_1040,h_527,al_c,q_90,usm_0.66_1.00_0.01/59e569_cd051484a6b6484c878dc0f7fc055c78.jpg')");
            }
            else {
               $("body").css("background-image","url('https://static.wixstatic.com/media/59e569_5653f5ff57064bf89b7b31ee85fde3a5.jpg/v1/fill/w_800,h_532,al_c,q_90,usm_0.66_1.00_0.01/59e569_5653f5ff57064bf89b7b31ee85fde3a5.jpg')");
            }
          };


//convert degrees into cardinal/ordinal directions            
           function degreesDirection(deg){

              if (deg > 5.63 && deg <= 50.62){
              return "NE";
              }
              else if (deg > 50.63 && deg <= 95.62){
              return "E";
              }
              else if (deg > 95.63 && deg <= 140.62){
              return "SE";
              }
              else if (deg > 140.63 && deg <= 185.62){
              return "S";
              }
              else if (deg > 185.63 && deg <= 230.62){
              return "SW";
              }
              else if (deg > 230.63 && deg <= 275.62){
              return "W";
              }
              else if (deg > 275.63 && deg <= 320.62){
              return "NW";
              }
              else{
              return "N";
            };
           };


$(document).ready(function(){
 
//get geolocation data
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {

//query open weather map API
          $.getJSON("http://api.openweathermap.org/data/2.5/weather?" + "lat=" + position.coords.latitude + "&lon=" + position.coords.longitude + "&units=imperial" + "&APPID=57a5a72171b9dedbcf2ed19869746bbc", function(result) {

//feed API results into HTML elements
            city.html(result.name);
            icon.attr("src", "http://openweathermap.org/img/w/" + result.weather[0].icon + ".png");
            tempF.html(Math.round(result.main.temp) + "F");
            tempC.html(Math.round((result.main.temp - 32) * (5 / 9)) + "C");
            desc.html(result.weather[0].description);
            hum.html((result.main.humidity) + "%");
            wind.html(Math.round(result.wind.speed) + "mph");
            windDir.html(degreesDirection(result.wind.deg));


            
//buttons to allow user to click through all background images (because they're cool)        
            $("#sun").click(function (){
              $("body").css("background-image","url('http://eskipaper.com/images/welcome-summer-1.jpg')");
            });
            
            $("#moon").click(function (){
              $("body").css("background-image","url('https://hughsblog.files.wordpress.com/2010/08/img_3298.jpg')");
            });
            
            $("#up").click(function (){
              $("body").css("background-image","url('https://upload.wikimedia.org/wikipedia/commons/4/48/Dokan_Mountain_at_Sunrise.JPG')");
            });
            
            $("#down").click(function (){
              $("body").css("background-image","url('http://cdn.pcwallart.com/images/beach-sunset-painting-wallpaper-1.jpg')");
            });
            
            $("#rain").click(function (){
              $("body").css("background-image","url('http://familygoesout.com/wp-content/uploads/Paper-Boats-Rain.jpg')");
            });
            
            $("#earth").click(function (){
              $("body").css("background-image","url('http://www.nasa.gov/sites/default/files/thumbnails/image/24609260915_a840b027e5_o.jpg')");
            });
            
             //call background function           
           changeBackground((new Date().getHours()), (result.weather[0].id), (result.main.temp));
            
          });
         });
      }
  });
            
          
!
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