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 class="container">
  <h1 class="text-center" id="intro">Your Local Weather</h1>
  <!--Weather Icon-->
  <div class="d-flex justify-content-center">
    <img id="weather-icon">
  </div>
  <!--Temperature-->
  <div class="d-flex justify-content-center" style="margin: 30px">
    <div id="temp"></div>
    <button id="tempButton" class="btn btn-primary">convert °C</button>
  </div>
  <!--Main Three Row-->
  <div class="d-flex justify-content-center" style="padding-bottom: 40px;">
    <div id="location" class="bubble">
    </div>
    <div id="weather" class="bubble">
    </div>
    <div id="wind" class="bubble">
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-color: black;
}

#temp {
  font-size: 1.5em;
  /*Makes it on same line, like span*/
  display: inline-block;
  /*Sets it in middle, vertically*/
  vertical-align: middle;
  margin-right: 20px;
  /*For the text*/
  color: #afb913;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

.bubble {
  margin: 0px 5px;
  padding: 30px 20px;
  border-radius: 10px;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.4);
  font-size: 1.5em;
  /*For the text*/
  color: #afb913;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

#intro {
  margin: 40px;
  color: #afb913;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}
#button {
  height: 3em;
  width: 8em;
  border-radius: 30px;
  z-index: 100;
  cursor: pointer;
}
#button:hover {
  pointer: cursor;
}
.btn {
  border-radius: 20px;
}
.btn:hover {
  cursor: pointer;
}
#weather-icon {
  height: 7em;
  width: auto;
}

.loader,
.loader:after {
  border-radius: 50%;
  width: 10em;
  height: 10em;
}
.loader {
  margin: 60px auto;
  font-size: 10px;
  position: relative;
  text-indent: -9999em;
  border-top: 1.1em solid rgba(255, 255, 255, 0.2);
  border-right: 1.1em solid rgba(255, 255, 255, 0.2);
  border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);
  border-left: 1.1em solid #ffffff;
  -webkit-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-animation: load8 1.1s infinite linear;
  animation: load8 1.1s infinite linear;
}
@-webkit-keyframes load8 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes load8 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
#loadingDiv {
  position: absolute;
  top: 100px; 
  width: 100%;
  height: 100%;
  background-color: #000; 
}

@media screen and (min-width: 320px) {
  html {
    font-size: 10px;
  }
}
@media screen and (min-width: 480px) {
  html {
    font-size: 12px;
  }
}
@media screen and (min-width: 1224px) {
  html {
    font-size: 16px;
  }
}

              
            
!

JS

              
                $(document).ready(() => {
  
  $('body').append('<div style="" id="loadingDiv"><div class="loader">Loading...</div></div>');

  setTimeout(removeLoader, 6000); 
  
  function removeLoader(){
    $( "#loadingDiv" ).fadeOut(500, function() {
      // fadeOut complete. Remove the loading div
      $( "#loadingDiv" ).remove(); //makes page more lightweight 
  });  
}
  var celsTemp;
  
  function convertToFarenheit(temp) {
    return (temp * 1.8 + 32).toFixed(2);
  }
  
 // Change Farenheight to Celsius
 $("#tempButton").on("click", () => {
   if ($("#tempButton").text() === "convert °F") {
     // Change button to read Celsius
     $("#tempButton").text("convert °C");
     // Convert temp to F
     document.getElementById("temp").innerHTML = (celsTemp * 1.8 + 32).toFixed(2) + " °F";
   } else {
     // Change button to read F
     $("#tempButton").text("convert °F");
     // Convert temp to C
     document.getElementById("temp").innerHTML = celsTemp + " °C";
   }
 });
  
// Windspeed
function degToCompass(num) {
    var val = parseInt((num/22.5)+.5);
    var arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"];
    return arr[(val % 16)];
}

// If browser supports navigation....
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(position => {
    // Function to check if status of fetch is OK
    const status = response => {
      if (response.status >= 200 && response.status < 300) {
        return Promise.resolve(response);
      } else {
        return Promise.reject(new Error(response.statusText));
      }
    };

    // Fetches weather from API
    fetch(
      `https://fcc-weather-api.glitch.me/api/current?lat=${position.coords
        .latitude}&lon=${position.coords.longitude}`)
      .then(status)
      .then(response => response.json())
      .then(responseData => {
        // Get temp
        celsTemp = responseData.main.temp;
        var farTemp = convertToFarenheit(celsTemp);
        // Get city
        var city = responseData.name
        // Get country
        var country = responseData.sys.country;
        // Get weather
        var weather = responseData.weather[0].description;
        // Get wind degree
        var windDeg = responseData.wind.deg;
        // Get wind Speed
        var windSpeed = responseData.wind.speed;
        // Get weather icon
        var weathIcon = responseData.weather[0].icon;
      
        // Set temperature
        document.getElementById("temp").innerHTML = farTemp + " °F";
        // Set city, country
        document.getElementById("location").innerHTML = city + ", " + country;
        // Set weather
        document.getElementById("weather").innerHTML = "Condition: " + weather;
        // Set wind
        document.getElementById("wind").innerHTML = "Wind: " + degToCompass(windDeg) + " " + windSpeed + " knots";
        // Set icon image
        $('#weather-icon').attr("src", weathIcon);
       })
      .catch(error => {
        console.log(`Error: ${error}`);
      });
  });
} else {
  document.getElementById("data").innerHTML =
    "Geolocation is not supported in this browser";
}

});
              
            
!
999px

Console