css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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 lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Weather App</title>
  </head>
  <body>
    <div class="container" id="locContainer">
      <div id="spinner">
        <i class="fa fa-spinner fa-spin fa-4x"></i>
        <p>Loading...</p>
      </div>
      <div class="row text-center" id="locCityStateRow">
        <i class="fa fa-location-arrow" style="font-size:20px"></i><h1 id="locHeading"></h1>
      </div>
      <div class="row text-center" id="locDateRow">
        <h3 id="currentDate"></h3>
      </div>
      <div class="row text-center" id="locTimeRow">
        <h3 id="currentTime"></h3>
      </div>
    </div>
    <div class="container-fluid outputContainer" id="outputContainer" style="display:none">
      <div class="row text-center">
        <label class="radio-inline">
          <input type="radio" name="tempRadioButtons" id="fTemp" value="fTemp" checked="true">&#8457;</input>
        </label>
        <label class="radio-inline">
          <input type="radio" name="tempRadioButtons" id="cTemp" value="cTemp">&#8451;</input>
        </label>
      </div>
  <div class="row outputRow">
    <div class="col-md-2 outputCol">
      <div class="innerOutput">
        <div class="row panelHeadingRow">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h2 class="page-header forecastHeading">Today</h2>
            </div>
            <div class="panel-body">
              <div id="currentForecastSection" class="text-center" style="display:none">
                <h3 id="forecastHeading"></h3><img src="" id="forecastHeadingIcon"></img>
              <h1><span id="tempHeading" class="tempLabel"></span><span id="tempHeadingSignSpan" class="tempSign">&#8457;</span></h1>
              <div class="hiLowDiv">
                <h4>Hi: <span id="highForecastSpan" class="tempLabel"></span><span id="highForecastTempSign" class="tempSign">&#8457;</span></h4>
                <h4>Lo: <span id="lowForecastSpan" class="tempLabel"></span><span id="lowForecastTempSign" class="tempSign">&#8457;</span></h4>
                <h4>Precipitation: <span id="precForecastSpan"></span></h4>
                <h4>Dewpoint: <span id="dewPoint" class="tempLabel"></span><span id="dewPointTempSign" class="tempSign">&#8457;</span></h4>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-md-8 outputCol">
    <div class="innerOutput">
      <div class="row panelHeadingRow" id="forecastHeadingRow">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h2 class="page-header forecastHeading">3 Day Forecast</h2>
          </div>
          <div class="panel-body">
            <ul class="list-group" id="extendedForecastListGroup" style="display:none"></ul>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-md-2 outputCol">
    <div class="innerOutput">
      <div class="panel-heading">
        <h2 class="page-header forecastHeading">Wind</h2>
      </div>
      <div class="panel-body">
        <div id="windSection" class="text-center">
          <h3 id="windHeading"></h3>
          <h4 id="windSpeed" style="display:inline-block"></h4>
          <h4 id="windDirection" style="display:inline-block"></h4>
          <h4><span id="windChill"></span></h4>
        </div>
      </div>
    </div>
  </div>
  </div>
</div>
</body>
</html>
            
          
!
            
              body {
  background: url('http://studeri.org/wp-content/uploads/2015/01/blue-sky-with-sun.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  font-family: 'Open Sans', sans-serif;
  color: #FFFFFF;
}


/* Classes */

.panel {
  background-color: transparent !important;
  border: 0 !important;
}

.panel-heading {
  background-color: transparent !important;
  padding-top: 0 !important;
  border: 0 !important;
  color: #FFFFFF !important;
}

.list-group-item {
  background-color: transparent;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  font-size: 1.3em;
}

@media (min-width: 320px) {
  .outputContainer {
    position: relative;
    margin-top: 15px;
  }
}

@media (min-width: 992px) {
  .outputContainer {
    position: absolute;
    bottom: 0;
    width: 100%;
  }
}

.outputRow {
  height: 100% !important;
}

.outputCol {
  height: 100% !important;
  padding-left: 5px;
  padding-right: 5px;
}

.hiLowDiv {
  padding-top: 30px;
}

.innerOutput {
  background-color: rgba(0, 0, 0, 0.35);
  height: 100%;
  background-clip: content-box;
  padding-top: 5px;
}

.panelHeadingRow {
  padding-left: 15px;
  padding-right: 15px;
}
.progress {
    text-align: center;
}
.progress-bar {
  transition: width .3s;
}
.forecastHeading {
  font-size: 2em;
  font-weight: 200;
  margin-top: 20px !important;
}
#tempHeading {
  font-size: 2em;
  font-weight: 300;
}
.tempBtnSelect {
  
}


/* ID's */
#spinner {
  position: absolute;
  top: 70%;
  left: 50%;
}
#locMap {
  width: 600px;
  height: 350px;
  max-height: 100%;
  max-width: 100%;
  margin: 0 auto;
}
#locContainer {
  position: relative;
  top: 15px;
}
#locHeading {
  display: inline;
  vertical-align: middle;
  padding-left: 10px;
}
#locTimeRow {
  display: none;
}
#locDateRow {
  display: none;
}
#locCityStateRow {
  display: none;
}
            
          
!
            
              /**
* Event Listeners 
**/

// Document Ready
$(document).ready(function(){
  $(this).ajaxStop(function() {
    $('#spinner').hide();
  });
  $('input[type=radio][name=tempRadioButtons]').change(function(){
    var btnId = $(this).prop('id');
    calculateTemp(btnId);
  });
  startTime();
  getLocation();
});

/**
* Functions
**/

function getLocation() {
  var tempObj;
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position){
      tempObj = {};
      tempObj.lat = position.coords.latitude;
      tempObj.lon = position.coords.longitude;
      getWeather(tempObj);
    });
  }
}

function getWeather(location) {
  var endpoint = 'https://api.wunderground.com/api/d4ba8fbded665688/forecast/conditions/q/';
  var endTags = '.json';
  var params = location.lat + ',' + location.lon;
  var finalUrl = endpoint + params + endTags;
  $.ajax({
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      "Accept": "application/json"
    },
    url: finalUrl,
    method: 'GET',
    success: function(response) {
      $('#outputContainer').show();
      var htmlBody = '';
      var count = 0;
      console.log(response);
      $('#locHeading').text(response.current_observation.display_location.city + ', ' + response.current_observation.display_location.state_name);
      var formattedDate = response.current_observation.local_time_rfc822.substring(0,11).split(' ');
      if(formattedDate.length === 3) {
        $('#currentDate').text(formattedDate[0] + ' ' + formattedDate[2] + ' ' + formattedDate[1]); 
      } else {
        $('#currentDate').text(response.current_observation.local_time_rfc822);
      }        
      $('#locCityStateRow').css('display','block').addClass('animated zoomIn');
      count += 300;
      setTimeout(function(){
        $('#locDateRow').css('display','block').addClass('animated zoomIn');
      }, count);
      count += 300;
      setTimeout(function(){
        $('#locTimeRow').css('display','block').addClass('animated zoomIn');
      }, count);
      // Populated Today Forecast Section
      $('#forecastHeading').text(response.current_observation.weather);
      $('#forecastHeadingIcon').attr('src',response.current_observation.icon_url);
      $('#tempHeading').text(Math.round(Number(response.current_observation.temp_f)).toString());
      $('#highForecastSpan').html(response.forecast.simpleforecast.forecastday[0].high.fahrenheit);
      $('#lowForecastSpan').html(response.forecast.simpleforecast.forecastday[0].low.fahrenheit);
      $('#precForecastSpan').html(response.forecast.simpleforecast.forecastday[0].pop + ' %');
      $('#dewPoint').html(response.current_observation.dewpoint_f);
      $('#currentForecastSection').show().addClass('animated fadeInUp');

      // Populate Extended Forecast Section
      for(var i = 0; i < response.forecast.simpleforecast.forecastday.length; i++) {
        if(i === 0) {
          continue;
        } else {
          htmlBody += '<li class="list-group-item">';
          htmlBody += '<div class="row" style="display:flex;align-items:center">';
          htmlBody += '<div class="col-xs-4">' + response.forecast.simpleforecast.forecastday[i].date.weekday + '</div>';
          htmlBody += '<div class="col-xs-4 text-center">';
          htmlBody += '<img src="' + response.forecast.simpleforecast.forecastday[i].icon_url + '">' + '</img>';
          htmlBody += '</div>';
          htmlBody += '<div class="col-xs-4 text-right">';
          htmlBody += '<span class="tempLabel">' + response.forecast.simpleforecast.forecastday[i].high.fahrenheit + '</span><span class="tempSign">&#8457;</span>' + ' / ' + '<span class="tempLabel">' + response.forecast.simpleforecast.forecastday[i].low.fahrenheit + '</span><span class="tempSign">&#8457;</span>';
          htmlBody += '</div>';
          htmlBody += '</div>';
          htmlBody += '</li>';
        }
      }
      $('#extendedForecastListGroup').html(htmlBody);
      $('#extendedForecastListGroup').css('display','block').addClass('animated','fadeIn');

      // Populate Wind Information
      $('#windHeading').text(response.current_observation.wind_string);
      if(response.current_observation.wind_mph !== 0) {
        $('#windSpeed').text(response.current_observation.wind_mph + ' mph');
        $('#windDirection').text(response.current_observation.wind_dir); 
      }
      if(response.current_observation.windchill_f !== 'NA' && response.current_observation.windchill_c !== 'NA') {
        $('#windChill').html('Wind Chill: ' + response.current_observation.windchill_f + ' &#8457;'); 
      }
      $('#windSection').css('display','block').addClass('animated fadeInUp');

      var maxHeight = 0;

      $(".innerOutput").each(function(){
        if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
      });

      $(".innerOutput").height(maxHeight);

    }
  });
}

function calculateTemp(btnId) {
  var $tempObjList = $('.tempLabel');
  console.log($tempObjList);
  var $tempSignList = $('.tempSign');
  var calcResult = 0;
  var tempSign;
  $tempObjList.each(function() {
    var currentTemp = Number($(this).text());
    if(btnId === 'fTemp') {
      calcResult = Math.round((currentTemp * 9/5) + 32);
      tempSign = '&#8457;';
    } else if (btnId === 'cTemp') {
      calcResult = Math.round((currentTemp - 32) * 5/9);
      tempSign = '&#8451;';
    }
    $(this).text(calcResult.toString());
  });
  $tempSignList.each(function(){
    $(this).html(tempSign);
  });
}

function startTime() {
  var today = new Date();
  var h = today.getHours();
  console.log(h);
  var m = today.getMinutes();
  var dd = 'AM';
  if(h >= 12) {
    h = h - 12;
    dd = 'PM';
  } else if(h < 10 && h > 0) {
    h = '0' + h;
  }
  if(h == 0) {
    h = 12;
  }
  m = m < 10 ? '0' + m : m;
  document.getElementById('currentTime').innerHTML = h + ":" + m + ' ' + dd;
  t = setTimeout(function () {
    startTime()
  }, 20000);
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console