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

              
                <div id="container">
  <h1 class="text-center">Local Weather App</h1>

  <div id="weatherBox" class="text-center">
    <img src="https://cdn.japanoblog.com/img/spinner.gif" alt="Hang on..." id="spinner" />
    <div id="weatherReport" class="hide">
      <div id="leftBox" class="col-xs-6">
        <div id="reportWeather"></div>
        <div id="reportTemp"></div>
        <div class="row" id="reportTempRange">
        <div id="tempHigh" class="col-xs-6"></div>
        <div id="tempLow" class="col-xs-6"></div>
        </div>
      </div>
      <div id="rightBox" class="col-xs-6">

        <div id="reportCity"></div>
        <div id="reportCondition"></div>
        <div class="row panel panel-default">
          <div class="panel-heading">Wind</div>
          <div id="reportWindSpeed" class="col-xs-6"></div>
          <div id="reportWindDirection" class="col-xs-6"><i class="wi wi-wind-direction"></i></div>
        </div>
        <div class="row panel panel-info">
          <div class="panel-heading">Pressure</div>
          <div id="reportHumidity" class="col-xs-6"></div>
          <div id="reportBarom" class="col-xs-6"></div>
        </div>

      </div>
    </div>

  </div>
</div>
<footer class="text-center">
  <div id="update" class="small"></div>
  made with <i class="fa fa-heart"></i> and <i class="fa fa-coffee"></i><br/>by <a href="/kode29" target="_blank">Kyle M. Perkins
  </footer>
              
            
!

CSS

              
                * {
  transition: all 0.5s ease-in-out;
}

body {
  background: #ccc;
  padding-top: 2%;
  padding-bottom: 2%;
  font-family: "Comfortaa", cursive;
  background: url("//cdn.kmp.link/img/abstract-geometric-background.png");
  background-size: cover;
  transition: all 1.5s ease-in-out;
}

h1{
  color: rgba(255,255,255,.8);
}
#weatherBox {
  padding: 20px;
  width: 50%;
  margin: 3% auto 2% auto;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 5px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
  overflow: auto;
}
#reportWeather {
  font-size: 12vw;
}
#reportTemp, #reportCity{
  font-size: 3vw;
}
#reportTempRange{
  margin-top: 10px;
}

#rightBox{
  font-size: 2vw;
}
#rightBox #reportWindSpeed{
  line-height: 6vw;
}
#rightBox #reportWindDirection{
  font-size: 4vw; 
}
.panel, reportTempRange{
  font-size: 1.5vw;
}

#reportTemp a, #update {
  cursor: pointer;
}

              
            
!

JS

              
                var LAT, LNG, weatherAPI;

// Weather Vars
var temp, tempType = "C"; // fcc-weather-api reports in C by default
var weather, city, country, condition, tempHigh, tempLow, barom, humidity, windSpeed, windDirection;
var timer;

$(function() {
  function updateTemp() {
    $("#reportTemp").html(
      temp + "&deg; <a id='tempDegrees' >" + tempType + "</a>"
    );
    $("#tempHigh").html("High: " + tempHigh + "&deg; " + tempType);
    $("#tempLow").html("Low: " + tempLow + "&deg; " + tempType);
  }

 function updateWeather(){
 weatherAPI =
      "https://fcc-weather-api.glitch.me/api/current?lat=" +
      LAT + "&lon=" + LNG;
   // alert("LAT: "+LAT+" | LNG: "+LNG);

    // This gets the Town/Weather from the Glitch API
    $.getJSON(weatherAPI, function(data) {
      $("#spinner").hide();
      $("#weatherReport").removeClass("hide");

       // General weather condition (sunny, rain, etc)
      weather = data.weather[0].main.toLowerCase();
       // Error-catch, to work with the weather icons
      if (weather.indexOf("clouds") !== false)
        weather = weather.replace("clouds", "cloudy");
      if (weather.indexOf("sunny") !== false)
        weather = weather.replace("sunny", "day-sunny");
      
      // Override test
      //weather = "rain"; // try "meteor"!
      $("#reportWeather").html("<i class='wi wi-" + weather + "'></i>");

      // temperature
      temp = Math.floor(data.main.temp); //fcc-weather-api reports in C
      tempHigh = data.main.temp_max;
      tempLow = data.main.temp_min;
      updateTemp();
      
      // geographical location
      city = data.name;
      country = data.sys.country;
      $("#reportCity").html(city + ", " + country);
      
      // Condition (light rain, mostly sunny, etc)
      condition = data.weather[0].description;
      $("#reportCondition").html(condition);
      
      // Barometer/humidity
      barom = data.main.pressure;
      $("#reportBarom").html("<i class='wi wi-barometer'></i> "+barom+" mbar");
      humidity = data.main.humidity;
      $("#reportHumidity").html("<i class='wi wi-humidity'></i> "+humidity+"%");
      
      // Wind
      windSpeed = data.wind.speed;
      $('#reportWindSpeed').html("<i class='wi wi-strong-wind'></i> " + windSpeed +" m/s")
      windDirection = data.wind.deg;
      $('#reportWindDirection i').css("transform", "rotate("+windDirection+"deg)");
      
      // load background
      var background
      switch (weather){
        case "rain":
        case "rainy":
          background = "//cdn.kmp.link/img/rain-275317_1280.jpg";
          $('h1').css('color', 'rgba(0,0,0,.5)');
          break;
        case "day-sunny":
          background = "//cdn.kmp.link/img/10916124814_7e60824587_h.jpg";
          $('h1').css('color', 'rgba(0,0,0,.5)');
          break;
        case "cloud":
        case "cloudy":
          background = "//cdn.kmp.link/img/sun-203792_1280.jpg";
          break;
        default:
          background = "//cdn.kmp.link/img/lago-di-limides-3025780_1280.jpg";
      }
      
      $('body').css('background', 'url("'+background+'") no-repeat');
      $('body').css('background-size', 'cover'); // needed to keep scale
    });
          
     var d = new Date();

     $('#update').html("Last Updated: "+d+" | <a id='updateNow'>Update Now</a>");
     timer = setTimeout(updateWeather, 60000); // run every 60 seconds
  }
  
  function updateNow(){
     clearTimeout(timer);
    updateWeather();
  }
  
 $('footer').on('click', '#updateNow', function(){
    event.preventDefault();
   tempType = "C"; //for now. Later, it may be updated to keep conversion
    updateNow();
  });
  
  var startPos;
  var geoSuccess = function(position) {
    startPos = position;
    // Get the users Lat/Long
    LAT = startPos.coords.latitude;
    LNG = startPos.coords.longitude;

    updateWeather();
  }

  // If the user won't let us find them, or an error
  var geoError = function(error) {
    console.log("Error occurred. Error code: " + error.code);
    // error.code can be:
    //   0: unknown error
    //   1: permission denied
    //   2: position unavailable (error response from location provider)
    //   3: timed out
    var msg = "";
    switch (error.code) {
      case 0:
        msg = "Unknown error occured.";
        break;
      case 1:
        msg = "Darn! You won't let us find you!";
        break;
      case 2:
        msg = "Oops. We can't seem to find you.";
        break;
      case 3:
        msg = "Error: Timed out";
        break;
    }
    $("#weatherReport").html(
      '<div class="alert alert-danger"><i class="fa fa-warning"></i> ' +
        msg +
        "</div>"
    );
  };

  navigator.geolocation.getCurrentPosition(geoSuccess, geoError);

  //var APIKey = "AIzaSyAFxf1qGiBY9gIjTgYvMdxWHFoYJHqD-P4";
  //var googleMaps = "https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key="+ APIKey;

  function convertCtoF(c) {
     return Math.round(c * (9 / 5) + 32);
  }
  function convertFtoC(f) {
   return Math.round((f - 32) * (5 / 9));
  }

  $("#reportTemp").on("click", "#tempDegrees", function(e) {
    e.preventDefault();
    if (tempType == "C") {
      // convert C to F
      temp = convertCtoF(temp);
      tempHigh = convertCtoF(tempHigh);
      tempLow = convertCtoF(tempLow);
      tempType = "F";
    } else {
      // convert F to C
      temp = convertFtoC(temp);
      tempHigh = convertFtoC(tempHigh);
      tempLow = convertFtoC(tempLow);
      tempType = "C";
    }
    updateTemp();
  });
});

              
            
!
999px

Console