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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

HTML

              
                <body>
  <div class="container-fluid">
    <div id="currentLocation" class="currentLocation">Loading...</div>
    <div id="weatherIcons" class="weatherIcons">
      <i></i>
    </div>
    <div id="currentWeather" class="currentWeather"></div>
    <div class="currentTemperature"><span id="currentTemperature">&deg;C</span></div>
     </div>
</body>
              
            
!

CSS

              
                body {
  background-color: #007CBD;
  color: #faebd7;
  text-align: center;
  font-family: 'Raleway', sans-serif;
  margin: 50px 0 auto;
  letter-spacing: 3px;
  font-weight: 300;
}

.container-fluid {
  display: inline-block;
}

.currentLocation {
  font-size: 300%;
  margin: 25px auto;
}

.weatherIcons {
  font-size: 120px;
  margin: 0 auto 40px;
}

.currentWeather {
  margin: 0 auto 25px;
  font-size: 200%;
}

.currentTemperature {
  font-size: 60px;
  margin: 0 auto 15px;
  display: inline-block;
  cursor: pointer;
  color: #fc3;
}

              
            
!

JS

              
                $(document).ready(function() {
  // Check whether browser supports Geolocation API or not
  if (navigator.geolocation) {
    // Supported
    navigator.geolocation.getCurrentPosition(getPosition);
  } else {
    // Not supported
    alert("Oops! This browser does not support HTML Geolocation.");
  }

  function getPosition(position) {
    let lat = position.coords.latitude;
    let lon = position.coords.longitude;

    //Call to weather API
    const API_KEY = "e188b6a2a5b9a44694ce486159c34452";
    let url =
      "https://api.openweathermap.org/data/2.5/weather?units=metric&lat=" +
      lat +
      "&lon=" +
      lon +
      "&APPID=" +
      API_KEY;
    $.getJSON(url, function(weatherData) {
      let currentLocation = weatherData.name;
      let currentTemperature = Math.floor(weatherData.main.temp);
      let currentWeather = weatherData.weather[0].description;
      let weatherIcon = weatherData.weather[0].icon;
      let temp_max = Math.floor(weatherData.main.temp_max);
      let temp_min = Math.floor(weatherData.main.temp_min);
      
      $("#currentLocation").html(currentLocation);
      $("#currentTemperature").html(currentTemperature + "°C");
      $("#currentWeather").html(currentWeather);

      //Prepend icons into our icon class
      //We want to prepend our ID with an icon depending on the weather
      $(".weatherIcons").addClass(getIcon(weatherIcon));

      function getIcon(weatherIcon) {
        let iconsMap = {
          "01d": "wi wi-day-sunny",
          "02d": "wi wi-day-cloudy",
          "03d": "wi wi-day-sunny-overcast",
          "04d": "wi wi-cloud",
          "09d": "wi wi-rain",
          "10d": "wi wi-day-showers",
          "11d": "wi wi-day-thunderstorm",
          "13d": "wi wi-day-snow",
          "50d": "wi wi-day-fog",

          "01n": "wi wi-night-clear",
          "02n": "wi wi-night-partly-cloudy",
          "03n": "wi wi-cloudy",
          "04n": "wi wi-night-cloudy",
          "09n": "wi wi-night-alt-showers",
          "10n": "wi wi-night-rain",
          "13n": "wi wi-night-snow",
          "50n": "wi wi-night-fog"
        };
        return iconsMap[weatherIcon];
      }

      //Convert between C and F
      function getTemperature () {
      let celsius = currentTemperature;
      let fahrenheit = Math.floor(celsius * 1.8 + 32);
      let showF = false;

      $("#currentTemperature").click(function() {
        showF = !showF;
        if (showF) {
          $("#currentTemperature").html(fahrenheit + "°F");
        } else {
          $("#currentTemperature").html(celsius + "°C");
        }
      });
    }
    getTemperature();

    function setColors() {
    let colors = {
              morning: "#44BFFF",
              noon: "#007CBD",
              night: "#19120A"
            };
    let currentTime = new Date().getHours();
            if (currentTime >= 6 && currentTime <= 12) {
              $("body").css("background-color", colors.morning);
            }
              else if (currentTime >= 12 && currentTime <= 18) {
              $("body").css("background-color", colors.noon);
            }
                else {
              $("body").css("background-color", colors.night);
            }
          }
    setColors();
    }); //getJSON
  } //getPosition
}); //documentReady

              
            
!
999px

Console