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

              
                  <!-- ==========================
    Fonts
  =========================== -->
<link href="https://fonts.googleapis.com/css?family=Proza+Libre" rel="stylesheet">

  <!-- ==========================
    CSS
  =========================== -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet">

  <!-- ==========================
    APP - START
  =========================== -->
  <div class="container">
    <div class="row">
      <div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 col-xs-12 weather">
        <h1 class="text-center">Local Weather App</h1>
        <hr>
        <div class="row">
          <div id="leftBox" class="col-md-6 col-sm-6 col-xs-6"></div>

          <div id="rightBox" class="col-md-6 col-sm-6 col-xs-6"></div>

        </div>
        <p class="text-right"><input id="changeUnit" type="checkbox" data-toggle="toggle" data-on="°C" data-off="°F" data-onstyle="primary" data-offstyle="danger" checked></p>
        <hr>
        <p class="text-center copyright">Created by <strong>Miljan Djordjevic</strong> &copy; 2016</p>
      </div>
    </div>
  </div>
  <!-- ==========================
    APP - END
  =========================== -->

  <!-- ==========================
    JS
  =========================== -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<script src="https://use.fontawesome.com/794fa4c80f.js"></script>
              
            
!

CSS

              
                body {
  font-family: 'Proza Libre', sans-serif;
}

p {
  font-size: 25px;
}

.weather {
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 1px solid #ccc;
  margin-top: 10px;
  padding: 0 25px;
}

.icons {
  width: 30px;
  padding: 2px;
  background-color: #eee;
  border-radius: 5px;
}

.temperature {
  font-size: 80px;
}

.copyright {
  margin: 25px;
  font-size: 16px;
}

@media screen and (max-width: 768px) {
  .weather {
    margin-top: 0;
  }
  
  p {
    font-size: 16px;
  }

  .temperature {
    font-size: 25px;
  }
}
              
            
!

JS

              
                // Coordinates of Belgrade, Serbia
var lat = 44.8;
var lon = 20.47;

function getWeather() {
  var url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=62a08954c13096ce415fec2d1d32d021";
    $.getJSON(url, function(json) {
      var currentWeather = [];

      // Get weather icon
      var getIcon = json.weather[0].icon;
      var weatherIcon = '<img src="https://openweathermap.org/img/w/'+ getIcon +'.png">';

      // Get weather description
      var weatherDesc = $.trim(json.weather[0].description);
      if (weatherDesc) {
        // This cannot work on codepen
        // $("body").css({"background-image": "url('imgs/" + weatherDesc + ".jpg')",
        //               "background-repeat": "no-repeat",
        //               "background-size": "cover"});
        var url;
        switch (weatherDesc) {
          case "clear sky":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582827/weather/clear_sky_jh8fwm.jpg";
            break;
          case "few clouds":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582825/weather/few_clouds_nqnyv6.jpg";
            break;
          case "scattered clouds":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582826/weather/scattered_clouds_ofb4qs.jpg";
            break;
          case "broken clouds":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582824/weather/broken_clouds_yvsjif.jpg";
            break;
          case "overcast clouds":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477584825/weather/overcast_clouds.jpg";
            break;
          case "light rain":
            url = "https://res.cloudinary.com/miljan/image/upload/v1478099892/weather/ligth_rain_xj64k7.jpg";
            break;
          case "rain":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582830/weather/rain_wpkexu.jpg";
            break;
          case "shower rain":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582830/weather/shower_rain_om8l0q.jpg";
            break;
          case "snow":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582830/weather/snow_cwqxyl.jpg";
            break;
          case "mist":
            url = "https://res.cloudinary.com/miljan/image/upload/v1477582825/weather/mist_xegz8y.jpg";
            break;
          default:
            url = "";
        }
        $("body").css({"background-image": "url(" + url + ")",
              "background-repeat": "no-repeat",
              "background-size": "cover"});
      }

      // Get humidity
      var weatherHumidity = json.main.humidity + " %";

      // Get pressure
      var weatherPressure = json.main.pressure + " hpa";

      // Get wind speed
      var weatherWindSpeed = json.wind.speed + " m/s";

      // Get wind direction
      var weatherWindDegree = json.wind.deg;
      var windNames = ["North", "North-Northeast", "Northeast", "East-Northeast", "East", "East-Southeast", "Southeast", "South-Southeast", "South", "South-Southwest", "Southwest", "West-Southwest", "West", "West-Northwest", "Northwest", "North-Northwest"];
      var windCompass = Math.round((weatherWindDegree - 11.25) / 22.5);
      var weatherWindDirection = windNames[windCompass];

      // Get weather temperature
      var temperature = json.main.temp; // Kelvin
      var celsius = Math.round(temperature - 273.15) + "°C";
      var fahrenheit = Math.round(temperature * 1.8 - 459,67) + "°F";
      var weatherTemterature = celsius;

      // Change temperature unite
      $("#changeUnit").on("change", function() {
        if(weatherTemterature === celsius) {
          weatherTemterature = fahrenheit;
          $(".temperature").html(weatherTemterature);
        } else {
          weatherTemterature = celsius;
          $(".temperature").html(weatherTemterature);
        }
      });

      // Get country
      var country = json.sys.country;

      // Get location
      var location = json.name;

      // Show weather values
      var dataLeftBox = "";
      var dataRightBox = "";

      dataLeftBox = "<p><img class='icons' src='https://res.cloudinary.com/miljan/image/upload/v1477653566/weather/marker_cytqt8.png' title='Location' alt='Location'><strong> " + location + "</strong>, " + country + "</p>";
      dataLeftBox += "<p><img class='icons' src='https://res.cloudinary.com/miljan/image/upload/v1477653566/weather/humidity_scishm.png' title='Humidity' alt='Humidity'> " + weatherHumidity +"</p>";
      dataLeftBox += "<p><img class='icons' src='https://res.cloudinary.com/miljan/image/upload/v1477653566/weather/pressure_hzfd9e.png' title='Pressure' alt='Pressure'> " + weatherPressure +"</p>";
      dataLeftBox += "<p><img class='icons' src='https://res.cloudinary.com/miljan/image/upload/v1477653566/weather/wind_cqjiad.png' title='Wind' alt='Wind'> " + weatherWindDirection + " (" + weatherWindSpeed +")</p>";

      dataRightBox = "<p class='text-right'><span class='temperature'><strong> " + weatherTemterature + "</strong></span></p>";
      dataRightBox += "<p class='text-right'>" + weatherIcon + " " + weatherDesc +"</p>";

      // Append weather to #getWeather
      $("#leftBox").html(dataLeftBox);
      $("#rightBox").html(dataRightBox);
  });
}

$(document).ready(function() {
  if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function (position) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;
        getWeather();
      });
        getWeather(); 
    } 
});

              
            
!
999px

Console