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="container">
<h3 id="loading">Loading...</h3>
<header>
  <h2 id="place">New York</h2>
  <h3 id="time"></h3>

  <section id="forecast">
    <div>
      <h1 id="temp" title="click to convert unit C/F"><span>0</span></h1>
    </div>
    <div><i id="icon" class="wi wi-day-cloudy"></i></div>
    <div id="phw">
      <h3 id="p"><i class="wi wi-thermometer"></i><span>0</span> hPa</h3>
      <h3 id="h"><i class="wi wi-humidity"></i><span>0</span>% humidity</h3>
      <h3 id="w"><i class="wi wi-strong-wind"></i><span>0</span> m/s</h3>
    </div>
    <p class="description"></p>
  </section>
</header>
</div>
              
            
!

CSS

              
                * {box-sizing: border-box}
html, body {height: 100%}
#loading {
  position: absolute;
  top: 45%;
  left: 45.5%;
}

body {
  background: #6441A5;
  // background: linear-gradient(to left, #6441A5 , #2a0845);
  color: #ecf0f1;
  font-family: 'Roboto', 'Open Sans', sans-serif, monospace;
  font-size: 30px;
  font-weight: 300;
}

h2, h3 {padding: .5em .25em}
h1 {font-size: 2.5em}
h2 {font-size: 1.5em}
h3 {font-size: .6em}
p {font-size: .5em}

.container {
  display: flex;
  height: 100%;
  align-items: center;
}

header {
  display: none; // To fadeIn with jQuery
  width: 100%;
}
#place, #time {text-align: center}

#forecast {
  max-width: 650px;
  width: 90%;
  margin: 20px auto;
  padding: 40px 0;
//  background: rgba(0,0,0,.5); // for layout testing
  text-align: center;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  
  div {
    margin: auto;
    width: 33%;
  }
  
  #temp {
    position: relative;
    cursor: pointer;
    &:after {
      content: '°';
      font-size: 0.7em;
      position: absolute;
    }
  }
  #temp, #icon {font-size: 5em}
  
   #phw {
     padding-left: 25px;
     text-align: left;
     i {margin-right: 1.5em} // space between icon and text
     white-space: nowrap;
   }
  
  .description {
    text-transform: capitalize;
    background: rgba(0,0,0,.6);
    padding: 10px;
    border-radius: 3px;
    margin-top: 5%;
  }
}

@media screen and (max-width: 680px) {
  body {font-size: 20px}
  #forecast {max-width: 500px}
}
@media screen and (max-width: 460px) {
  header {overflow: hidden}
  #forecast {
    padding: 0;
    max-width: 400px;
    display: block;
    div {
      float: left;
      min-width: 100px;
      width: 50%;
      padding: 0;
      margin-bottom: 30px;
    }
    
    #phw {
      text-align: left;
      clear: left;
      float: none;
      margin-top: 10px; // No idea why, but it works
    }
    
    .description {
      position: absolute;
      bottom: 20px;
      text-align: center;
      width: 90%;
      font-size: .8em;
    }
  }
}
              
            
!

JS

              
                var api = "https://api.openweathermap.org/data/2.5/weather",
units= "metric",
ipApi = "https://ipinfo.io/json",
iconClass = 'wi wi-owm-day-', // weather icons
city, country,
bg, date;

var day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function uTime() {
  date = new Date();
  var timeStr = day[date.getDay()] + ', ' + month[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getHours() + ':' + date.getMinutes();
  $('#time').text(timeStr);
}
uTime();
setInterval(uTime, 1000);

function setWeather(w) {
  var weather = w.weather[0];
  if (date.getHours() >= 18 
      || date.getHours() <= 6) {
    iconClass = 'wi wi-owm-night-';
  }
  var temp = Math.round(w.main.temp),
      pressure = w.main.pressure,
      humid = w.main.humidity,
      wind = w.wind.speed;
  
  $('#place').text(city + ', ' + country);
  $('#temp span').text(temp);
  $('#icon').removeClass().addClass(iconClass + weather.id);

  $('#p span').text(pressure);
  $('#h span').text(humid);
  $('#w span').text(wind);
  $('.description').text(weather.description);
/*    background stuff;
    if (this.temp < 34 && this.temp > 18 && this.time.getHours() < 16) {
      bg = 'http://livehdwallpaper.com/wp-content/uploads/2014/10/Good-Morning-Photos.jpg';
    }

    if (bg) {
      $('body').css('background', "url('" + bg + "')");
    }
*/
}

function getWeather() {
  $.getJSON(api, function(data) {
    setWeather(data);
    stopAnimation();
  });
}

function getLocation() {
  return $.getJSON(ipApi, function(data) {
    city = data.city;
    country = data.country;
    api += `?q=${city},${country}&APPID=5be662184a5f66d241c04ec58eab34ec&units=${units}`;
    api = encodeURI(api);
  });
}

getLocation()
  .done(getWeather);

var u = 'c';
function convert(t) {
  if (u == 'c') {
    u = 'f';
    return Math.round(t * 9/5 + 32);
  } else {
    u = 'c';
    return Math.round( (t - 32) * 5/9 );
  }
}

$('#temp').click(function(){
  $('#temp span')
    .fadeOut(null, ()=> {
      $('#temp span').text(convert( $(this).text() ))
        .fadeIn();
    });
});

function stopAnimation() {
  $('#loading').fadeOut();
  $('header').fadeIn();
}
              
            
!
999px

Console