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

              
                 <h2>Local Weather</h2>


<body id="background">
    <h1 id="location"></h1>
    <p class="large" id="temp"></p>
    <h2 id="weather"></h2>
  
    <div class="buttons bottom-space">
      <a class="btn btn-default btn-sm" href="#" role="button" id="moreLess">
      </a>
      <a class="btn btn-default btn-sm" href="#" role="button" id="degType">
      </a>
    </div>
    <div class="container">
      <div id="moreData">
        <p class="murica" id="windMph"></p>
        <p class="world" id="windKm"></p>
        <p id="windDir"></p>
        <p class="world" id="precipMm"></p>
        <p class="murica" id="precipIn"></p>
        <p id="humidity"></p>
        <p class="murica" id="feelsLikeF"></p>
        <p class="world" id="feelsLikeC"></p>
        <p class="murica" id="visibleMiles"></p>
        <p class="world" id="visibleKm"></p>
      </div>
    </div>
</body>
              
            
!

CSS

              
                body {
  color: white;
  font-family: Kanit;
  text-align: center;
  height: 100%;
}

h1 {
  color: rgba(255, 255, 255, .9);
  font-size: 70px;
  text-shadow: 7px 2px 10px rgba(0, 0, 0, .8);
}

h2 {
  color: rgba(255, 255, 255, .9);
  font-size: 35px;
  text-shadow: 2px 2px 5px rgba(0, 0, 0, .9);
  margin: 5px 5px 5px 5px;
}

p {
  font-size: 15px;
  color: rgba(255, 255, 255, .9);
  text-shadow: 2px 2px 5px rgba(0, 0, 0, .8);
}

a {
  color: rgba(255, 255, 255, .9);
  text-shadow: 2px 2px 5px rgba(0, 0, 0, .9);
}

a:hover {
  color: rgba(255, 255, 255, 1);
  text-shadow: 2px 2px 10px rgba(0, 0, 0, .9);
}

a:visited {
  color: rgba(255, 255, 255, .9);
}

#temp {
  transition-duration: .5s;
}

#background {
  background-image: none;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
}

.large {
  font-size: 100px;
  color: rgba(255, 255, 255, .9);
  text-shadow: 2px 5px 7px rgba(0, 0, 0, .8);
  margin: 5px 5px 5px 40px; 
}

.btn {
  border: 2px solid rgba(255, 255, 255, 1);
  width: 120px;
  margin: 20px;
}

.btn:hover {
  border: 2px solid rgba(255, 255, 255, .4);
}

.btn:active {
  color: rgba(255, 255, 255, .6);
}

.buttons {
  flex-grow: 0;
}

.container {
  bottom: 0;
}

.bottom-space {
  margin-bottom: 10px;
}

#moreData {
  opacity: 0;
  transition: 2s ease-in-out;
}

.America {
  display: none;
}

.world {
  display: block;
}
              
            
!

JS

              
                $(document).ready(function() {
  let lat;
  let long;

  // Grab user's coordinates
  $.getJSON("https://ipinfo.io", function(data) {
    let coords = data.loc.split(",");
    lat = coords[0];
    long = coords[1];

    // API for JSON object containing user's local data
    let api = "https://api.apixu.com/v1/current.json?key=11bce5444db54a6a875202355172905&q=" + lat + "," + long + "";

    // Get user's local weather data
    $.getJSON(api, function(data2) {
      let location = data2.location.name;
      let country = data2.location.country;
      let weather = data2.current.condition.text;
      let farenheit = Math.round(data2.current.temp_f);
      let celcius = Math.round(data2.current.temp_c);
      let degrees;
      let moreLess = true;
      let windMph = data2.current.wind_mph;
      let windKm = data2.current.wind_kph;
      let windDir = data2.current.wind_dir;
      let precipMm = data2.current.precip_mm;
      let precipIn = data2.current.precip_in;
      let humidity = data2.current.humidity;
      let feelsLikeF = Math.round(data2.current.feelslike_f);
      let feelsLikeC = Math.round(data2.current.feelslike_c);
      let visibleMiles = data2.current.vis_miles;
      let visibleKm = data2.current.vis_km;
      let changeList = document.getElementById("moreData");
      let murica = document.getElementById("murica");
      let world = document.getElementById("world");
      let current = data2.current.condition.code;
      let imageUrl;
      let weatherWords = weather.split(' ');
      let keywords;
      
      // Filter weather keywords for image query
      for (let i = 0; i < weatherWords.length; i++){
        if (weatherWords[i] == 'or' || weatherWords[i] == 'with'){
          i++;
        }
        if (weatherWords[i] == 'Partly'){
          weatherWords[i] = 'sun';
        }
        if (i > 0){
          keywords+=weatherWords[i];
        } else {
          keywords = weatherWords[i];
        }
        if (i != weatherWords.length-1){
          keywords += ',';
        } 
      }
      
      // Insert keywords into Url for JSON data
      let unsplash = "https://api.unsplash.com/photos/random/?query=" + keywords + "&orientation=landscape&count=10&client_id=6e25be67996e81171f583afc336e40f3c755f16b3a9db7dc2107bd9016b80f67";
                  
      $.getJSON(unsplash, function(data3){
        
        // Set background image from random selection
        document.getElementById("background").style.backgroundImage="Url(" + data3[0].urls.full + ")";
        
      });      

      // Toggle ºC & ºF
      function changeDegrees() {
        if (degrees == true) {
          degrees = false;
        } else {
          degrees = true;
        }
        if (degrees == true) {
          $("#degType").html("Show ºC");
          $("#temp").html(farenheit + "º");
          $(".world").hide();
          $(".murica").show();
        } else {
          $("#degType").html("Show ºF");
          $("#temp").html(celcius + "º");
          $(".murica").hide();
          $(".world").show();
        }
      }

      // Toggle More & Less Data
      function changeMoreLess() {
        if (moreLess == true) {
          moreLess = false;
        } else {
          moreLess = true;
        }
        if (moreLess == true) {
          $("#moreLess").html("More Data");
          changeList.style.opacity = "0";
        } else {
          $("#moreLess").html("Less Data");
          changeList.style.opacity = "1";
        }
      }

      // Use location to determine initial unit type
      if (country == "United States of America") {
        degrees = false;
        changeDegrees();
      } else {
        degrees = true;
        changeDegrees();
      }

      // Display user's local temperature & conditions
      $("#location").html(location);
      $("#moreLess").html("More Data");
      $("#weather").html(weather);
      $("#windMph").html("Wind Speed: " + windMph + " Mph");
      $("#windKm").html("Wind Speed: " + windKm + " Km/h");
      $("#windDir").html("Wind Direction: " + windDir);
      $("#precipMm").html("Precipitation: " + precipMm);
      $("#precipIn").html("Precipitation: " + precipIn);
      $("#humidity").html("Humidity: " + humidity);
      $("#feelsLikeF").html("Feels Like: " + feelsLikeF + "º");
      $("#feelsLikeC").html("Feels Like: " + feelsLikeC + "º");
      $("#visibleMiles").html("Visibility: " + visibleMiles + " Mi");
      $("#visibleKm").html("Visibility: " + visibleKm + " Km");

      // 'Click' functions for toggle buttons
      $("#degType").on("click", function() {
        changeDegrees();
      });
      $("#moreLess").on("click", function() {
        changeMoreLess();
      });
      
    });
  });
});
              
            
!
999px

Console