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.

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

            
              <div class="spinner load">
</div>

<main class="container">
  <h1>Free C<span id="icon"></span>de Camp</h1>
  <h2>Weather Forecast</h2>
  <div id="city"></div>
  <div class="temp">
    <span id="temp"></span><span id="metric"></span>
  </div>
  <div id="weatherType"></div>

  <div class="search">
    <label for="city-search">Find a forecast</label>
    <input type="text" id="city-search" placeholder="e.g. New York, NY" autofocus><br>
  </div>
</main>

<footer>
  <a href='https://www.linkedin.com/in/simongjetaj' target='_blank'>By <span>Simon</span></a>
</footer>

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyACfwNoW8oFr3ImAMkMaB04jKhE7jjQjo4&libraries=places,geometry">
</script>
            
          
!

CSS

            
              * {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Skranji", cursive;
  font-size: calc(18px + 0.1vw);
  line-height: calc(3em + 0.1vh);
  text-shadow: 0.6px 0.6px 1px #fff;
  background-size: cover;
  background-position: center;
  min-height: 100vh;
}

.load {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: #fff
  url("https://www.creditmutuel.fr/cmne/fr/banques/webservices/nswr/images/loading.gif")
    no-repeat center center;
}

.container {
  max-width: 700px;
  margin: 0 auto;
  text-align: center;
}

h1 {
  font-size: 2.2em;
  word-spacing: 0.1em;
}

h2 {
  font-weight: 100;
  margin-top: -0.5em;
  letter-spacing: 0.025em;
  word-spacing: 0.05em;
}

span#icon {
  position: relative;
  top: 0.2em;
}

span#metric {
  color: #1e88e5;
  font-weight: bold;
  text-shadow: 0.8px 0.2px 0.1px #000;  
}

#metric:hover {
  cursor: pointer;
  font-size: 1.1em;
}

.temp {
  margin-top: 1.5em;
}

#city {
  margin-top: 1.5em;
}

#weatherType {
  margin-top: 1.5em;
}

.search {
  margin-top: 1.5em;
}

input[type="text"] {
  font-size: 0.8em;
  width: 14em;
  line-height: 1.6em;
  border: none;
  border-radius: 5px;
  box-shadow: 0 0 15px 1px #1e88e5;
  transition: all 0.3s;
}

input[type="text"]:focus {
  outline: none;
  box-shadow: 3px 3px 30px 4px #1e88e5;
}

footer {
  margin-top: 3em;
  text-align: center;
}

footer a {
  text-decoration: none;
  color: #000;
}

footer a:hover {
  text-decoration: underline;
}

footer span:hover {
  color: #1e88e5;
}

            
          
!

JS

            
              // locating you
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    let lat = position.coords.latitude;
    let lon = position.coords.longitude;
    getWeather(lat, lon);
  });
} else {
  alert("Sorry, Geolocation is not supported by this browser.");
}

// getting the weather data using fetch()
function getWeather(lat, lon) {
  let api =
    `https://fcc-weather-api.glitch.me/api/current?lat=${lat}&lon=${lon}`;
  fetch(api)
    .then(blob => blob.json())
    .then(data => {
      let cTemp = data.main.temp;
      let city = data.name;
      let country = data.sys.country;
      let weatherType = data.weather[0].main;
      let weatherDesc = data.weather[0].description;
      let icon = data.weather[0].icon;
      querySelector("#city").innerHTML = city + ", " + country;
      querySelector("#weatherType").innerHTML =
        weatherType + " (" + weatherDesc + ")";
      querySelector("#icon").innerHTML =
        "<img alt='o' src=" + icon + ">";
      let fTemp = (cTemp * 9 / 5 + 32).toFixed(1);
      let toggleCF = false;
      let temp = querySelector("#temp");
      let metric = querySelector("#metric");
      temp.innerHTML = cTemp;
      metric.innerHTML =  " &#8451;";
      
      metric.addEventListener("click", function() {
      if (toggleCF === false) {
        temp.innerHTML = fTemp;
        metric.innerHTML = " &#8457;";
        toggleCF = true;
      } else {
        temp.innerHTML = cTemp;
        metric.innerHTML = " &#8451;";
       toggleCF = false;
      }
    });
    // console.log(weatherType);
    switch(weatherType) {
      case "Clear":
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/photo-1452561802015-953ab78c4526?dpr=1&auto=compress,format&fit=crop&w=1477&h=&q=80&cs=tinysrgb&crop=)";
        break;
      case "Clouds": 
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/44/xKNCBEgSTUGbgBoYgJ90_Skyline.jpg?dpr=1&auto=compress,format&fit=crop&w=751&h=&q=80&cs=tinysrgb&crop=)";
        break;
      case "Rain":
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/photo-1477847616630-cf9cf8815fda?dpr=1&auto=compress,format&fit=crop&w=750&h=&q=80&cs=tinysrgb&crop=)";
        break;  
      case "Mist":
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/30/ny-filtered.jpg?dpr=1&auto=compress,format&fit=crop&w=1508&h=&q=80&cs=tinysrgb&crop=)";
        break;
      case "Fog":
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/photo-1494054457339-2022c634b1ae?dpr=1&auto=compress,format&fit=crop&w=1570&h=&q=80&cs=tinysrgb&crop=)";
        break;
      case "Thunderstorm":
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/photo-1498595707991-4fc87268b184?dpr=1&auto=compress,format&fit=crop&w=1489&h=&q=80&cs=tinysrgb&crop=)";
        break;
      case "Snow":
        querySelector("body").style['background-image'] = 'url(https://images.unsplash.com/photo-1468476775582-6bede20f356f?dpr=1&auto=compress,format&fit=crop&w=1366&h=&q=80&cs=tinysrgb&crop=)';
        break;
      default: 
        querySelector("body").style["background-image"] = "url(https://images.unsplash.com/photo-1469433791803-c2719135f970?dpr=1&auto=compress,format&fit=crop&w=750&h=&q=80&cs=tinysrgb&crop=)";
        break;
    }
    querySelector('.spinner').classList.remove('load');
    })
    .catch(err => alert(err));
}

// making easy to get elements from the DOM and interecting with HTML
function querySelector(element) {
  return document.querySelector(element);
}

// getting the weather for the searched city, -google api
let searchBox = new google.maps.places.Autocomplete(
  document.querySelector("#city-search")
);
searchBox.addListener("place_changed", function() {
  let locale = searchBox.getPlace();
  let lat = locale.geometry.location.lat();
  let lon = locale.geometry.location.lng();
  querySelector('.spinner').classList.add('load');
  getWeather(lat, lon);
});


            
          
!
999px

Console