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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <div class="hero is-fullheight" id="bg">
  <div class="hero-body">
    <div class="container has-text-centered">
      <div class="pane">
        <h1 class="title" id="place">Loading...</h1>
        <h2 class="subtitle" id="weather">Loading...</h2>
        <h3 id="temperature">Loading...</h3>
        <i id="icon" class="fa fa-circle-o-notch fa-spin fa-2x fa-fw"></i>
        <span class="sr-only" id="loading-snowflake">Loading...</span>
        <p id="data"></p>
      </div>

      <p class="by">by <a target="_blank" href="http://dmy.li">Damiano Casula</a>
    </div>
  </div>
</div>
            
          
!
            
              h1.title, h2.subtitle, h3, i {
  color: #555;
}

h2.subtitle::first-letter {
  text-transform: uppercase;
}

#bg {
  background-image: url('https://static.pexels.com/photos/25833/pexels-photo-25833.jpg');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.pane {
  margin: auto auto;
  padding: 40px 0;
  width: 40%;
  background-color: rgba(255, 255, 255, 0.45);
  border-radius: 7px;
}

@media (max-width: 768px) {
  .pane {
    margin: 0;
    padding-top: 40px;
    width: 100%;
    border-radius: 0px;
  }
}

#temperature {
  max-width: 80px;
  margin: auto;
}

#temperature:hover {
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
}

.by {
  color: white;
  margin-top: 20px;
  text-align: center;
}

a:hover {
  color: #bbb;
}

            
          
!
            
              $(document).ready(function () {
  (function($) {
      $.fn.clickToggle = function(func1, func2) {
          var funcs = [func1, func2];
          this.data('toggleclicked', 0);
          this.click(function() {
              var data = $(this).data();
              var tc = data.toggleclicked;
              $.proxy(funcs[tc], this)();
              data.toggleclicked = (tc + 1) % 2;
          });
          return this;
      };
  }(jQuery));

  var apiKey = "3698638a4a836bff8d1a4b66a27bf5c4";
  var baseURL = "http://api.openweathermap.org/data/2.5/weather";

  var bg = $("#bg"), bgImage = "", icon = $("#icon"), iconClass = "";
  var fahrenite, celsius;

  function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function (position) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;

        $.getJSON(baseURL + "?lat=" + lat + "&lon=" + lon + "&APPID=" + apiKey, function (data) {
          fahrenite = Math.round(((data.main.temp - 273.15) * (9 / 5)) + 32);
          celsius = Math.round(data.main.temp - 273.15);


          $("#place").text(data.name + ", " + data.sys.country);
          $("#weather").text(data.weather[0].description);
          $("#temperature").text(fahrenite + " °F");

          switch (data.weather[0].description) {
            case "clear sky":
              bgImage = "https://static.pexels.com/photos/196464/pexels-photo-196464.jpeg";
              iconClass = "fa-sun-o";
              break;

            case "few clouds":
              bgImage = "https://static.pexels.com/photos/25833/pexels-photo-25833.jpg";
              iconClass = "fa-sun-o";
              break;

            case "scattered clouds":
              bgImage = "https://static.pexels.com/photos/147534/pexels-photo-147534.jpeg";
              iconClass = "fa-cloud";

              break;

            case "broken clouds":
              bgImage = "https://static.pexels.com/photos/122408/pexels-photo-122408.jpeg";
              iconClass = "fa-cloud";
              break;

            case "shower rain":
              bgImage = "https://images.pexels.com/photos/112641/pexels-photo-112641.jpeg";
              iconClass = "fa-tint";
              break;

            case "rain":
              bgImage = "https://static.pexels.com/photos/39811/pexels-photo-39811.jpeg";
              iconClass = "fa-tint";
              break;

            case "thunderstorm":
              bgImage = "https://static.pexels.com/photos/9466/pexels-photo.jpg";
              iconClass = "fa-bolt";
              break;

            case "snow":
              bgImage = "https://static.pexels.com/photos/24642/pexels-photo-24642.jpg";
              iconClass = "fa-snowflake-o";
              break;

            case "mist":
              bgImage = "https://static.pexels.com/photos/48694/pexels-photo-48694.jpeg";
              iconClass = "fa-bars";
              break;

            default:
              bgImage = "https://static.pexels.com/photos/25833/pexels-photo-25833.jpg";
              iconClass = "fa-sun-o";
          }

          bg.css("background-image", "url('" + bgImage + "')");
          icon.removeClass("fa-spin").removeClass("fa-fw").removeClass("fa-circle-o-notch").addClass(iconClass);

        });
      }, function () {
        $("#data").html("<b>Failed</b>");
      });
    }
  }

  getLocation();

  $("#temperature").on("click", function () {
    $(this).clickToggle(function () {
      $(this).text(fahrenite + " °F");
    }, function () {
      $(this).text(celsius + " °C");
    });
  });
});

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

Console