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 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.

Quick-add: + add another resource

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.

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.

            
              <body>
  <div class="main">
    <div class="centered">
      <h1 id="city"></h1>
      <h2 id="temp"></h2>
      <h3 id="humidity"><h3>
      <h3 id="wind"></h3>  
   </div>
  </div>
</body
            
          
!
            
              body {
  background-color: #fff;
  font-family: 'Raleway', sans-serif;
  color: #fff;
}

h1 {
  font-weight: 100;
  font-size: 7em;
  margin-bottom: -55px;
}

h2 {
  font-size: 4em;  
}

h3 {
  font-size: 1.5em;
  font-weight: 200;
  margin-top: -10px;
}

.main {
  width: 1100px;
  margin: 20px auto 50px auto;
  text-align: center;
  padding:  5% 0;
}

.centered {
  padding: 10% 0;
}


/* Smartphones (portrait and landscape) ----------- */
@media screen
and (min-width : 320px) and (max-width : 480px) {
  .main {
  width: 400px;
}
  h1 {
    font-size: 2em;
  }
}
  
/* iPads (portrait and landscape) ----------- */
@media screen and (min-width : 481px) and (max-width : 1024px) {
  .main {
  width: 825px;
}
  h1 {
    font-size: 4em;
  }
}
 

            
          
!
            
               
//Displays the city, current temperature in celsius, humidity, and the //wind speed on the beaufort scale.
  
//Background color changes according to temperature

$(document).ready(function() {
  
  //Find visitors location: city name and longitude and latitude
  
  $.getJSON("http://ip-api.com/json", function(data) {
    $("#city").html(data.city);
    
    var lat = data.lat;
    var lon = data.lon;

    //Using the longitude and latitude obtained from the ip API to  
    //construct a query string for the openweathermap API

    $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=ec925ac254f9714f24db4cae4a8bb0e0", function(data) {
      
      //Convert temp from kelvin to celsius:
      var tempCelsius = Math.round(((data.main.temp) - 273.15));
      
      //wind speed    
      var windSpeed = data.wind.speed;
      var beaufort;
      
     //convert temp from kelvin to fahrenheit
     //var tempFahr = Math.round(((data.main.temp - 273.15)* 1.8 +32));
      
     //Using jQuery to change background color according to temperature
      
       if (tempCelsius >= 35){
			    $("body").css("background-color", "#ff5722");
		   }
       else if (tempCelsius >= 30 && tempCelsius <= 34) {
            $("body").css("background-color", "#ffc107");  
       }    
       else if (tempCelsius >= 20 && tempCelsius <= 29) {
            $("body").css("background-color", "#8bc34a");    
       }  
       else if (tempCelsius >= 10 && tempCelsius <= 19) {
            $("body").css("background-color", "#00bcd4"); 
       } 
       else {
            $("body").css("background-color", "#448aff");
       }  
      
     //Wind speed conversion from m/s to Beaufort scale

      if  (windSpeed >= 0.0 && windSpeed <= 1.8){
      beaufort = 1;
      }
      else if (windSpeed >= 1.9 && windSpeed <= 3.3){
      beaufort = 2;
      }
      else if (windSpeed >= 3.4 && windSpeed <= 5.4){
      beaufort = 3;
      }
      else if (windSpeed >= 5.5 && windSpeed <= 7.9){
      beaufort = 4;
      }
      else if (windSpeed >= 8.0 && windSpeed <= 11.0){
      beaufort = 5;
      }
      else if (windSpeed >= 11.1 && windSpeed <= 14.1){
      beaufort = 6;
      }
      else if (windSpeed >= 14.2 && windSpeed <= 17.2){
      beaufort = 7;
      }
      else if (windSpeed >= 17.3 && windSpeed <= 20.8){
      beaufort = 8;
      }
      else if (windSpeed >= 20.9 && windSpeed <= 24.4){
      beaufort = 9;
      }
      else if (windSpeed >= 24.5 && windSpeed <= 28.5){
      beaufort = 10;
      }
      else if (windSpeed >= 28.6 && windSpeed <= 32.6){
      beaufort = 11;
      }
      else {
      beaufort = 12;
     }
     
      //Using jQuery to populate the h1, h2, and h3 elements
      
      $("#temp").html(tempCelsius + "C");  
      $("#humidity").html("Humidity: " + data.main.humidity + "%");
      $("#wind").html("Beaufort: " + beaufort);
      

    });
  });
});

            
          
!
999px
Loading ..................

Console