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.

            
              <body>
<div class="container">
  <div id="error"></div>
  <div id="city"></div>
  <p><img src="http://calvarycentraloahu.com/codepen/thermometer90.png" alt="thermometer" height="45" width="45">
    Current Temp<div id="temperature"></div>  
  </p>
  <input id="convert-button" type="button" class="btn btn-lg btn-primary" value="Display: °F / °C" />
  <div id="results">    
    <p>Conditions<div id="condition"> </div></p>
    <p>Wind Speed<div id="wind-speed"></div></p>
   </div>     
  </div>
</body>
            
          
!
            
              body {
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #ff5d00; /*find color to match all backgrounds */
  font-family: 'arial', tahoma;
  font-weight: bold;
  min-width: 320px;
  text-align: center;
}

p {
  font-weight: bolder;
  padding-top: 1em;
  padding-bottom: -1.5em;
}
#container {
  min-height: 100%;
  position: relative;
}
#error {
	font-size: 1.5em;
	margin: 1em 0 0 2em;
  text-align: left;
}

#error a {
	color: #328CBF;
	text-decoration: underline;
}
#city {  
  background-color: rgba(147, 175, 196, .4);
  border: 2px solid #3f6aea;
  width: 100%; 
  text-align:  center;
  font-size: 2em;
 }
#temperature {
  font-size: 3em;
 }

#convert-button {
  margin-bottom: 2.5em; 
}
#results {
 margin-bottom: 2.5em; 
}
#condition,#wind-speed {
  background-color: rgba(147, 175, 196, .4);
  border: 2px solid #3f6aea;
  border-radius: 10%;
  display: inline-block;
  font-size: 1.2em;
  margin: .2em;
  min-height: 4em;
  min-width: 8em; 
  padding: 1.0em; 
  }
.wi {
  font-size: 2em;
}


            
          
!
            
              //you need to register your own API from openweathermap.org to get your location
var callback = '&APPID=0087cf6328ae7e22b636e954f877baea';
$(document).ready(function() {
  getLocation();
  $('#condition').html('<i class="fa fa-spinner fa-pulse fa-3x"></i>');
  $('#wind-speed').html('<i class="fa fa-spinner fa-pulse fa-3x"></i>');
});
function getLocation() {
  // freegeoip.net w/added ip address/json callback
  $.getJSON('https://freegeoip.net/json/66.75.108.18?callback=?', function(loc) {
    $('#city').text(loc.city + ', ' + loc.region_name + ', ' + loc.country_name);
    getWeather(loc.latitude, loc.longitude, loc.country_code);
  })
  .fail(function(err) {
    getWeather();
  });
}
function getWeather(lat, lon, countryCode) {
  var weatherAPI = 'https://api.openweathermap.org/data/2.5/weather?lat=' +
    lat + '&lon=' + lon + '&units=imperial' + '&type=accurate' + callback;
  $.getJSON(weatherAPI, function(weatherData) {
      // Also used by convert();
      temp = weatherData.main.temp.toFixed(0);
      tempC = ((temp - 32) * (5 / 9)).toFixed(0);

      var condition = weatherData.weather[0].description,
        id = weatherData.weather[0].id,
        speed = Number((weatherData.wind.speed * 0.86897624190816).toFixed(1)),
        deg = weatherData.wind.deg,
        windDir,
        iconClass,
        bgIndex,
        backgroundId = [299, 499, 599, 699, 799, 800],
        backgroundIcon = [
          'thunderstorm','sprinkle','rain','snow',
          'fog','night-clear','cloudy'
        ],
 //background images sources: find your own images
  backgroundImg = [       'http://calvarycentraloahu.com/codepen/storm_clouds.jpg',         'http://calvarycentraloahu.com/codepen/raindrops_window1000.jpg',         'http://calvarycentraloahu.com/codepen/rainy_day.jpg', 'http://calvarycentraloahu.com/codepen/snow.jpg',        'https://secure.static.tumblr.com/cc2c3f18b2d43b0c26cf1a52b5833e46/p0o9m4o/HGInxida1/tumblr_static_f58e6imgxs84c0coc4g4ww0gc_640_v2.gif',          'http://islandwebtek.com/codepen/day_sky1000.jpg',      'http://calvarycentraloahu.com/codepen/thick_clouds1000.jpg'
];
 backgroundId.push(id);
  bgIndex = backgroundId.sort().indexOf(id);
  $('body').css('background-image', 'url(' + backgroundImg[bgIndex] + ')');
  iconClass = backgroundIcon[bgIndex];
 //compass
 if (deg) {
 var index = Math.floor((deg / 22.5) + 0.5) % 16,
  compassDirections = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'
  ],
  windDir = compassDirections[index];
 } else {
  windDir = 'N';
 }
//temperature reading
 var fahrenheit = ['US', 'BS', 'BZ', 'KY', 'PL'];
 if (fahrenheit.indexOf(countryCode) > -1) {
 $('#temperature').text(temp + '° F');
 } else {
 }
//add wind and weather to html
$('#wind-speed').html(
 '<i class="wi wi-wind wi-from-' + windDir.toLowerCase() + '"></i><br>' +
 windDir + ' ' + speed + ' knots');
 $('#condition').html(
 '<i class="wi wi-' + iconClass + '"></i><br>' + condition);
})
.fail(function(err) {
alert('Cannot retrieve data \n' +
 'Please try again later.');
 });
}
//convert button: celsius / fahrenheit
$('#convert-button').click(function() {
  if ($('#temperature').text().indexOf('F') > -1) {
  $('#temperature').text(tempC + '° C');
 } else {
 $('#temperature').text(temp + '° F');
}
});



            
          
!
999px
Loading ..................

Console