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 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="weather">
  <canvas id="icon" width="64" height="64"></canvas>
  <h2>TimeZone:</h2><p id="timezone"></p>
  <h2>Description:</h2><p id="description"></p>
  <h2>Temperature:</h2><p id="temperature"></p>
  <button onclick="changeScale()" >Change Scale</button>
</div>

<script src="https://rawgithub.com/darkskyapp/skycons/master/skycons.js"></script>
              
            
!

CSS

              
                .weather {
  background-color: white;
  border: solid 1px black;
  padding: 10px;
  margin: auto;
  width: 50%;
  border: 3px solid black;
}

body {
  background: url('https://report.az/storage/news/2d24481fa1ef4a20e1a703f88f8400c4/aee96c6d-d63a-4f9a-897e-3213b477b5fe.jpg');
}
              
            
!

JS

              
                var APIKEY = '22bbde6414ada496401cb62696a8ac7e';
var API_URL = 'https://api.darksky.net/forecast/' + APIKEY + "/";
var API_EXCLUDE = '?units=si&lang=pt&exclude=minutely,hourly,alerts,flags';
var trickToFixCrossAccessControl = "&callback=?";
var scale = 'ºC';

var latitude = 0;
var longitude = 0;

function getTemperature(params) {
  $.getJSON(API_URL + params + API_EXCLUDE + trickToFixCrossAccessControl, function(data) {
      buildPageWithTemperatureInformation(data);
  });
}

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showLocation, function(error) {
      alert("error! :(");
      console.log(error);
    });
  }
}


function showLocation(position) {
  latitude = position.coords.latitude;
  longitude = position.coords.longitude;

  getTemperature(latitude + ',' + longitude);
}



function buildPageWithTemperatureInformation(data) {
  var description = data.currently.summary;
  var temperature = data.currently.temperature;
  var timezone = data.timezone;
  var time = data.currently.time;

  $('#temperature').text(temperature.toString().split('.')[0] + " " + scale);
  $('#description').text(description);
  $('#timezone').text(new Date(time));
  
  changeIcon(data.currently.icon);
}

function changeIcon(icon) {
  var skycon = new Skycons({"color":"black"})
  skycon.set("icon", icon);
  skycon.play();
}

function changeScale() {
  var temperature = $('#temperature').text().split(" ")[0];
  var finalTemperature = 0;
  if(scale === 'ºC') {
    finalTemperature = (temperature * 1.8) + 32;
    scale = 'ºF';
  }  else {
    finalTemperature = (temperature - 32) / 1.8;
    scale = 'ºC';
  }

  // change on the DOM
  $('#temperature').text(finalTemperature.toString().split('.')[0] + " " + scale);
}


//------------//

$(document).ready(function() {
  getLocation();
});
              
            
!
999px

Console