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 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

              
                <div class="full-page">
  <div class="layer" id="layerDiv">
  <div class="text-center">
    <h1 class="font-main">Weather</h1>


    <div class="row">
      <div class="columns small-centered small-4 medium-3 large-2">
        <ul class="button-group even-2 toggle round" data-toggle="buttons-radio">
          <li>
            <input type="radio" id="r1" name="r-group" checked data-toggle="button">
            <label class="button tiny unitBtn" for="r1"><span class="show-for-sr">&deg;C</span><i class="wi wi-celsius unitIcon"></i></label>
          </li>
          
          <li>
            <input type="radio" id="r2" name="r-group" data-toggle="button">
            <label class="button tiny unitBtn" for="r2"><span class="show-for-sr">&deg;F</span><i class="wi wi-fahrenheit unitIcon"></i></label>
          </li>
        </ul>
      </div>
    </div>
    <div class="display">
      <div class="columns small-12">
        <h2 class="font-secondary" id="location"></h2>
        <h3 class="font-secondary" id="description"></h3>
        <div class="columns small-12 medium-6 large-4  small-centered">

          <div class="columns small-12">
            <i id="mainIcon" class="animated fadeInUp wi"></i>
            <h2 class="font-secondary" id="temp"><span id="units"></span></h2>
          </div>

          <div class="columns small-12 extra-info">
            <div class="columns small-4">
              <i class="wi wi-humidity"></i>
              <h4 class="font-secondary" id="humidity"></h4>
            </div>
            <div class="columns small-4">
              <i class="wi wi-barometer"></i>
              <h4 class="font-secondary" id="baroPress"></h4>
            </div>
            <div class="columns small-4">
              <i class="wi wi-strong-wind"></i>
              <h4 class="font-secondary" id="windSpeed"></h4>

            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                button,
.button {
  background-color: rgba(52, 152, 219, 0.7);
  border-color: rgba(127, 140, 141, 1.0);
}

.unitIcon {
  font-size: 2em;
}

input[type="checkbox"] + label,
input[type="radio"] + label {
  display: inline-block;
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 15px;
}

input[data-toggle] {
  display: none;
}

input[data-toggle]:checked + label,
input[data-toggle]:checked + label:active {
  background-color: rgba(250, 128, 114, 0.8);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
}

#mainIcon {
  margin: 1.5rem 0 0.5rem 0;
  color: #fff;
  text-shadow: 2px 2px #000;
  font-size: 4em;
}

#temp {
  margin-bottom: 2rem;
}

.font-main {
  font-family: 'josefin sans', sans-serif;
  color: #ffffff;
  text-shadow: 2px 2px #000;
  font-size: 5em;
}

.font-secondary {
  font-family: 'Open Sans', sans-serif;
}

ul {
  list-style-type: none;
}

.extra-info i {
  font-size: 2em;
}

.border {
  border: 1px solid black;
}

.full-page {
  height: 100vh;
  min-height: 100%;
  background-size: cover;
}

.layer {
  background-color: rgba(236, 240, 241, 0.3);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                $(document).ready(function() {
  
  var lat,
    iconID,
    location,
    lon;
  var units = "&units=metric";
  var unitPick = "C&deg;";
  var windUnit = "m/s";
  var pressureUnit = "mb";

  getLocation();

  // Get location with geolocation
  function getLocation() {

    if (!navigator.geolocation) {
      console.log("geo error");
      altLocation();
    }

    function success(position) {
      lat = position.coords.latitude;
      lon = position.coords.longitude;
      console.log(lat,lon);
      getWeather();
    }

    function error() {
      altLocation();

    }

    navigator.geolocation.getCurrentPosition(success, error);
  }

  // Get location with IPinfo
  function altLocation() {
    $.getJSON('http://ipinfo.io', function(data) {
      console.log(data)

      lat = data.loc[0];
      lon = data.loc[1];
      location = data.city;
      getWeather();
    })
  }

  // Unit buttons
  $(".unitBtn").on("click", function() {
    unitPick = $(this).text();
    if (unitPick.indexOf("C") !== -1) {
      units = "&units=metric";
      windUnit = "m/s";
      pressureUnit = "mb";
      getWeather();
    } else if (unitPick.indexOf("F") !== -1) {
      units = "&units=imperial";
      windUnit = "mph";
      pressureUnit = "inHg";
      getWeather();
    }

  });

  function getWeather() {
    
    fetch('http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + '&appid=977c47562a4c5893ea88bbca1c425e98&mode') .then( response => {
      return response.json();
    })
    .then ( data => {
      // console.log("hi");
      // var html = "";
       console.log(data);
      });

//       var temperature = Math.round(json.main.temp);
//       var description = json.weather[0].description;
//       var weatherID = json.weather[0].id;
//       var iconClass = "wi-owm-" + weatherID;
//       var baroPress = json.main.pressure;
//       var humidity = json.main.humidity;
//       var windSpeed = json.wind.speed;
//       iconID = json.weather[0].icon;

//       getStyle();

//       $("#mainIcon").addClass(iconClass);
     
//       // use geolocation Location if IPinfo location returns empty
//       if (location === undefined) {
//          location = json.name;
//       }
      
//        $("#location").html(location);
//       $("#temp").html(temperature + unitPick);
//       $("#description").html((description).toUpperCase());
//       $("#humidity").html(humidity + "%");

//       // Pressure conversion 
//       if (pressureUnit == "mb") {
//         baroPress = json.main.pressure;
//       } else if (pressureUnit == "inHg") {
//         baroPress = baroPress * 0.0295300;
//       };

//       $("#baroPress").html(Math.round(baroPress) + pressureUnit);
//       $("#windSpeed").html(Math.round(windSpeed) + windUnit);
   // });

  }

  // Set weather specific background image

 // function getStyle() {
    var imageURL,
        textColor;
    console.log(iconID);
    switch (iconID) {
        
      // Clear Sky
      case "01d":
        imageURL = "https://images.unsplash.com/photo-1448818583842-3353f177e9b4?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=091181f8bc5f9453930919a7017f41d9";
        break;
      case "01n":
        imageURL = "https://images.unsplash.com/photo-1444080748397-f442aa95c3e5?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=209d2d52469dec829b005b9bbf7b102d";
        textColor = "white";
        $("#layerDiv").removeClass("layer");
        break;

        // Few clouds
      case "02d":
        imageURL = "https://images.unsplash.com/photo-1430778569142-43551f375f9a?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=cf9dd773103c393bd80b07910801dbd3";
        break;
      case "02n":
        imageURL = "https://images.unsplash.com/photo-1429305336325-b84ace7eba3b?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=3a86834eb7f4628c1f2ef234ee4d8279";
        textColor = "white";
        $("#layerDiv").removeClass("layer");
        break;

        // Scatered Clouds
      case "03d":
        imageURL = "https://images.unsplash.com/uploads/1412455906842d646f1ce/7bf17d33?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=cfd6d4bc76c77f002a4628a76fb1efcb)";
        break;
      case "03n":
        imageURL = "url(https://images.unsplash.com/photo-1452837850452-3974eda0fbe4?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=36da18310fcfb6566062937d0d415bf9";
        break;

        // Broken clouds?? Open weather api uses a dark cloud icon.. So that's what the images will show.. 
      case "04d":
        imageURL = "https://images.unsplash.com/photo-1447523264591-68112eb55c23?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=03edf887ebb77cdda57c035140984778";
        break;
      case "04n":
        imageURL = "https://images.unsplash.com/photo-1450766166778-e0a0e092d71b?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=eca9290828e5741ddc8668fb6dab72da";
        $("#layerDiv").removeClass("layer");
        textColor = "white";
        break;

        // Shower Rain
      case "09d":
        imageURL = "https://images.unsplash.com/photo-1457463968646-bbb6184dfedb?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=f7bd6d471031f5cdf1dcb42e6d5049ad";
        break;
      case "09n":
        imageURL = "https://images.unsplash.com/photo-1417008914239-59b898b49382?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=88d1c758b1ada959ba8f0c8c54ec44e1";
        break;

        // Rain
      case "10d":
        imageURL = "https://images.unsplash.com/photo-1438449805896-28a666819a20?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=75c6aea928bd3f4ab1daef5a797ec20d";
        break;
      case "10n":
        imageURL = "https://images.unsplash.com/photo-1449175334484-66563eaeec14?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=44e5ed1ea39077924b931f381b80e5dc";
        break;

        // Thunderstorm
      case "11d":
        imageURL = "https://images.unsplash.com/photo-1432927994002-af88b5da76a2?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=9b62b314102774e705bf166e9f6f9a71";
        break;
      case "11n":
        imageURL = "https://images.unsplash.com/photo-1447829172150-e5deb8972256?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=8f16ff0419362d842e41375d92ff8cf4";
        break;

        //snow
      case "13d":
        imageURL = "https://images.unsplash.com/photo-1431036101494-66a36de47def?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=56cdaadbf92590359edea1972024429a";
        break;
      case "13n":
        imageURL = "https://images.unsplash.com/photo-1423853978401-35df4077ff7d?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=6e753bb049e8cd68f4f981dcf11584d6";
        break;

        // Mist Fog
      case "":
        imageURL = "https://images.unsplash.com/photo-1430921688227-2c59c6489072?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=fcb5e015eba5d1af650a33da7a6ebe1f";
        break;
      case "":
        imageURL = "https://images.unsplash.com/23/do-the-dew.JPG?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=285e811bdef8560d7b47ceed1da5dec9";
        break;

    }
    $(".full-page").css("background-image", "url(" + imageURL + ")");
    $(".font-main, .font-secondary, body").css("color", textColor)
  }
}); // End doc ready
              
            
!
999px

Console