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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <html>
<head><meta name= "viewport" content = "width=device-width, initial-scale=1"></head>
<body>
  <div class = "weatherData text-center">
    <h1>What's your Weather?</h1>
    <ul class = "list-unstyled">
      <li class = "town" id = "city" ></li>
      <li class = "btn btn-default tempbtn" id = "fTemp" ></li>
      <li class = "description" id = "weather" ></li>
      <li class = "wind" id = "windSpeed" ></li>
    </ul>
  </div>
</body>
</html>
              
            
!

CSS

              
                body {
  max-width: 100%;
  overflow-x: hidden;
  background-size:cover;
  background-repeat:no-repeat;
  background-position: center center;
  background-attachment: fixed;
}
.weatherData{
 padding: 20px;
  border-radius: 5px;
  font-family: "Montserrat";
  color:white;
  background:rgba(0,0,0,.3);
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
  margin:5% 24% 0% 24%;
  min-width: 30%;
}
.town {
  font-size: 200%;
}

.description {
  text-transform: Capitalize;
  font-size: 150%;
  margin-top: 2%;
  margin-bottom: 2%;
}

.wind{
  font-size: 125%;
}

.tempbtn{
  border:none;
  margin-top: 2%;
  text-shadow:none;
  color:white;
  font-size: 200%;
  background:rgba(0,0,0,.4);
}

.tempbtn:hover{
  background-color:black;
  color:grey;
}
              
            
!

JS

              
                $(document).ready(function() {
  
 var long;
 var lat;
 var fTemp;
 var cTemp;
 var tempSwap = true;
 var fTempLabel;
 
  $.getJSON("https://ipapi.co/json/", function(data2){ 
    
 //Get long and lat data from api
    lat = data2.latitude;
    long = data2.longitude;
   
    
    //Below: Set api with the current user's long and lat. Then call it with getJSON
    var api = 'https://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+long+'&appid=33ab2ecaf2531e24cb1d742f0eb2cd88';
    
    $.getJSON(api, function(data){
    
    //Below: Get information from api and assign to variables
      var city = data.name;
      var weather = data.weather[0].description;
      var weatherMain = data.weather[0].main;
      var kTemp = data.main.temp;
      var windSpeed = data.wind.speed;
      var mphWindSpeed = (2.237*(windSpeed)).toFixed(1);
    
    //Convert Kevin into C and F
      fTemp = (Math.ceil((kTemp)*(9/5)-459.67));
      fTempLabel = (fTemp  + " &#8457");
      cTemp =  (Math.floor((kTemp - 273)));
    
    //Below: Apply information from api to HTML
      $("#city").html(city);
      $("#weather").html(weather);
      $("#windSpeed").html("Wind Speed:  " + mphWindSpeed + " mph");
      $("#cTemp").html(cTemp);
      $("#fTemp").html(fTempLabel);
    
    
    //Temp C F Switch on click
      $("#fTemp").click(function(){
       
      if (tempSwap === true){
        $("#fTemp").html(cTemp  + " &#8451");
        tempSwap = false;
        }
      else{
        $("#fTemp").html(fTemp  + " &#8457");
        tempSwap = true;
        }
       });
    
    //Apply background based on general weather or specific conditions
    if(weatherMain == "Clouds") {
       $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714177/Altocumulus-cloud_from_above_hronhz.jpg)');
    }
    else if(weatherMain == "Atmosphere") {
       $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714177/Altocumulus-cloud_from_above_hronhz.jpg)');
    }
    else if(weatherMain == "Clear"){
       $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714349/clear_kim2us.jpg)');
    }
    else if(weatherMain == "Drizzle"){
      $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485711683/rainy_jv2j3o.jpg)');
    }
     else if(weatherMain == "Rain"){
      $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485711683/rainy_jv2j3o.jpg)');
    }
    else if(weatherMain == "Thunderstorm"){
      $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714760/storm_sqqt8r.jpg)');
    }
     else if(weatherMain == "Snow"){
      $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714933/snow_c32nwe.jpg)');
    }
    
    else if(weatherMain == "Extreme"){
        if(weather == "tornado"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715160/tornado_mh6vnf.jpg)');
         }
        else if(weather == "tropical storm" || "hurricane"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715160/tornado_mh6vnf.jpg)');
         }
        else if(weather == "hot"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715513/hot_f6d2hd.jpg)');
         }
         else if(weather == "cold"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714933/snow_c32nwe.jpg)');
         }
         else if(weather == "windy"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715823/wind_uu5tex.jpg)');
         }
         else if(weather == "hail"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485714760/storm_sqqt8r.jpg)');
         }
    }
       else if(weatherMain == "Additional"){
        if(weather == "storm" || "hurricane" || "violent storm" || "severe gale"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715160/tornado_mh6vnf.jpg)');
         }
        else if(weather == "calm" || "light breeze" || "gentle breeze" || "fresh breeze" ){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485716263/calm_imm9v3.jpg)');
         }
         else if(weather == "strong breeze" || "moderate breeze" || "high wind" || "near gail" || "gale"){
         $('body').css('background-image', 'url(https://res.cloudinary.com/dtjqdtdyi/image/upload/v1485715823/wind_uu5tex.jpg)');
         }
       
    }
   });
  });
});


              
            
!
999px

Console