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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <body onload="getLocation()">
  <div class="container-fluid">
    <div class="row">
      <div class="col-xs-12 col-md-offset-3 col-md-6">
        <div class="purple_box">
          <h5 id="summaryIcon">
          </h5>
          <p id="summary"></p> <!–– Weather description -->
          <div class="row">
            <div class="col-md-4">
              <p id="cTemp"></p> <!–– Temperature -->
            </div>
            <div class="col-md-4">
            </div>
            <div class="col-md-4">
              <p id="humidity"></p> <!–– Humidity -->
            </div>
          </div>
          <div class="row">
            <input id ="tempToggle" checked="checked" data-toggle="toggle" type="checkbox" data-on="&degF" data-off="&degC" data-onstyle="default">
          </div>
        </div>
        <h5 class="text-center">Coded by japoemape. Data courtesy of <a href="https://darksky.net/" target="_blank">Dark Sky</a>.</h5>
      </div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                body {
  background-color: #e1dbdf;
  text-align: center;
}

.purple_box {
  display: block;
  background-color: #c2a9ba;
  padding: 2em;
  margin: 3em auto 3em auto;
  border: 1px solid #ccc;
  border-radius: 3px;
  text-align: center;
}

p {
  font-family: Megrim;
  font-size: 45px;
  color: #5f0e47;
}

i {
  font-size: 9em;
  padding: 20px;
  color: #5f0e47;
}

.wi-humidity {
  font-size: 40px;
}

.wi-thermometer-exterior {
  font-size: 40px;
}

.wi-day-sunny {
  font-size: 9em;
  padding: 20px;
  animation: spin 25s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

              
            
!

JS

              
                var x = document.getElementById("cTemp");
var y = document.getElementById("summaryIcon");
var z = document.getElementById("summary");
var a = document.getElementById("humidity");
var impTemp = "";
var metricTemp = "";
// JSONP
// CORS
// jQuery

// Get user's location in coordinates on page load
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  var lat = position.coords.latitude.toString();
  var long = position.coords.longitude.toString();

  //API vars to make JSON call
  var apiCall = "https://api.darksky.net/forecast/5f6d7c13a2c3177b29f5fed29f917fd5/";
  var geoLoc = lat + "," + long;
  var url = apiCall + geoLoc;

  //Get JSON data
  $.ajax({
    url: url,
    jsonp: "callback",
    dataType: "jsonp",
    success: function(data) {
      // metric and imperial temp
      impTemp = Math.floor(data.currently.temperature);
      metricTemp = Math.floor((impTemp - 32) * 5 / 9);

      // Display current temparature
      x.innerHTML = "<i class=\"wi wi-thermometer-exterior\"></i>" + impTemp + "&deg";
      a.innerHTML = Math.round(data.currently.humidity * 100) + "<i class=\"wi wi-humidity\"></i>";

      // Display description of weather
      var val = data.currently.icon;
      switch (val) {
        case "clear-day":
          y.innerHTML = "<i class=\"wi wi-day-sunny\"></i>";
          z.innerHTML = "clear";
          break;
        case "clear-night":
          y.innerHTML = "<i class=\"wi wi-night-clear\"></i>";
          z.innerHTML = "clear";
          break;
        case "rain":
          y.innerHTML = "<i class=\"wi wi-rain\"></i>";
          z.innerHTML = "rain";
          break;
        case "snow":
          y.innerHTML = "<i class=\"wi wi-snow\"></i>";
          z.innerHTML = "snow";
          break;
        case "sleet":
          y.innerHTML = "<i class=\"wi wi-sleet\"></i>";
          z.innerHTML = "sleet";
          break;
        case "wind":
          y.innerHTML = "<i class=\"wi wi-strong-wind\"></i>";
          z.innerHTML = "wind";
          break;
        case "fog":
          y.innerHTML = "<i class=\"wi wi-fog\"></i>";
          z.innerHTML = "fog";
          break;
        case "cloudy":
          y.innerHTML = "<i class=\"wi wi-cloudy\"></i>";
          z.innerHTML = "cloudy";
          break;
        case "partly-cloudy-day":
          y.innerHTML = "<i class=\"wi wi-day-cloudy\"></i>";
          z.innerHTML = "partly cloudy";
          break;
        case "partly-cloudy-night":
          y.innerHTML = "<i class=\"wi wi-night-cloudy\"></i>";
          z.innerHTML = "partly cloudy";
          break;
        case "hail":
          y.innerHTML = "<i class=\"wi wi-hail\"></i>";
          z.innerHTML = "hail";
          break;
        case "thunderstorm":
          y.innerHTML = "<i class=\"wi wi-thunderstorm\"></i>";
          z.innerHTML = "thunderstorm";
          break;
        case "tornado":
          y.innerHTML = "<i class=\"wi wi-tornado\"></i>";
          z.innerHTML = "tornado";
          break;
        default:
          y.innerHTML = "no data :\/"
          break;
      }
    }
  })
}

// Toggle between C and F
var myToggle = document.getElementById("tempToggle");
myToggle.onchange = function() {changeTemp()};

function changeTemp() {
  if (myToggle.checked === true) {
    x.innerHTML = "<i class=\"wi wi-thermometer-exterior\"></i>" + impTemp + "&deg";
  } 
  else if (myToggle.checked === false) {
    x.innerHTML = "<i class=\"wi wi-thermometer-exterior\"></i>" + metricTemp + "&deg";
  }
}
              
            
!
999px

Console