cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container">
  <div class="header text-center">
    <h1>Local Weather</h1>
    <p><span id="city"></span><span id="region"></span>&nbsp;<span id="country"></span></p>
  </div>
  <div class="row">

    <div class="col-md-6 text-center">
      <span id="temp"></span><button class='btn'>| &#176;C</button>
      <p><span id="conditions"></span></p>
    </div>
    <div class="col-md-6 text-center">
      <p><span id="icon"></span><br></p>
    </div>
  </div>
  <div id="credit" class="text-center">
    <p>Code and Design by Candice Davidson</p>
    <p>Geolocation by <a href="https://ipinfo.io">ipoinfo.io</a> | Weather data by <a href="http://openweathermap.org">openweathermap.org</a></p>
        </div>
    </div>
            
          
!
            
              html {
  height: 100%;
}

body {
  /* fallback */
  background-color: #86daf3;
  font-family: 'Raleway', sans-serif;
  font-size: 16px;
  color: #fff;
  height: 100%;
}

h1,
#temp {
  font-family: 'Megrim', sans-serif;
  font-size: 3em;
  font-weight: 800;
}

p {
  font-size: 2em;
}

.header p {
  margin: 50px 0;
}

#conditions {
  margin: 25px 0;
}

#temp {
  font-size: 4em;
}

.container {
  width: 600px;
  max-width: 100%;
}

.row {
  margin: 50px 0;
}

.btn {
  font-family: 'Megrim', sans-serif;
  padding: 10px 0 0 10px;
  border: 0;
  background: none;
  font-size: 2em;
  font-weight: 800;
  vertical-align: top;
}

.btn.focus,
.btn.hover,
button.btn.active,
.btn:focus,
.btn:hover,
button.btn:active {
  color: #fff;
  text-decoration: none;
  border: 0;
  outline: none;
}

#credit p {
  font-size: 1em;
}

#credit a {
  color: #fff;
  text-decoration: underline;
}
            
          
!
            
              $(document).ready(function () {

  var APIk = "c852eff24ce63a4936c2501cfe5124fc";
  var lat = "0";
  var lon = "0";

  $.getJSON("https://ipinfo.io/json/?callback=?", function (geo) {

    lat = geo.loc.split(",")[0];
    lon = geo.loc.split(",")[1];
    

    currentWeather(lat, lon);

    var city = geo.city;
    var region = geo.region;
    var country = geo.country;
    var latlong = geo.loc;  

    $('#city').html(city);
    $('#region').html(', ' + region);
    $('#country').html(', ' + country);
    $('#loc').html(', ' + latlong);
  });

  function currentWeather(x, y) { //get openweathermap.org data

    var weatherData = "https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat=" + x + "&lon=" + y + "&APPID=" + APIk + "&callback=?";

    $.getJSON(weatherData, function (data) {

      $("#icon").html('<img src=\"icons/' + data["weather"][0]["icon"] + '.png" alt="current weather"\>');

      var temp2f = ((data["main"]["temp"] - 273.15) * 9 / 5 + 32).toFixed(0);
      var temp2c = (data["main"]["temp"] - 273.15).toFixed(0);
      
      console.log(data["main"]["temp"]);

      bgcolor = (data["weather"][0]["icon"][2]);
      //bgcolor = "d";

      $("#temp").text(temp2f + '\xB0 F');

      $("button").click(function () {
        if ($('.btn').is(":contains('\xB0 F')")) {
          $("#temp").text(temp2f + '\xB0 F');
          $('.btn').html('| ' + '\xB0 C');
        } else {
          $("#temp").text(temp2c + '\xB0 C');
          $('.btn').html('| ' + '\xB0 F');
        }
      });

      var country = data.sys.country;
      var conditions = data.weather[0].main;
      var description = data.weather[0].description;

      $('#country').html(country);
      $('#conditions').html(conditions);
      $('#more').html(description);

      changeBackground(bgcolor);
    });

    function changeBackground(bgcolor) {
      if (bgcolor === "n") {
        document.body.style.backgroundColor = "#084363";
        document.body.style.background = "-webkit-linear-gradient(top, #062a42, #7176a0";
        document.body.style.background = "-webkit-gradient(linear, 0% 0%, 0% 100%, from(#062a42), to(#7176a0))";
        document.body.style.background = "-moz-linear-gradient(top, #2F2727, #1a82f7";
        document.body.style.background = "-ms-linear-gradient(top, #2F2727, #1a82f7";
        document.body.style.background = "-o-linear-gradient(top, #2F2727, #1a82f7";
      } else {
        document.body.style.backgroundColor = "#86daf3";
        document.body.style.background = "-webkit-linear-gradient(top, #86daf3, #e3b6ab";
        document.body.style.background = "-webkit-gradient(linear, 0% 0%, 0% 100%, from(#86daf3), to(#e3b6ab))";
        document.body.style.background = "-moz-linear-gradient(top, #86daf3, #e3b6ab";
        document.body.style.background = "-ms-linear-gradient(top, #86daf3, #e3b6ab";
        document.body.style.background = "-o-linear-gradient(top, #86daf3, #e3b6ab";

      }
    }
  }

}); 
            
          
!
999px
Loading ..................

Console