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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <HTML>

<HEAD>
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
  <link href="https://fonts.googleapis.com/css?family=Pattaya" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css" rel="stylesheet">
  <TITLE>Local Weather</TITLE>
</HEAD>

<BODY>
  <div class="weatherFont">
    <div class="weather text-center">
      <h1 class="text-center">Local Weather</h1>
    </div>
    <div class="row">
      <div id="geolocationText" class="col-xs-10 col-xs-offset-1 col-md-6 col-md-offset-3 bgWhite weather">Location loading</div>
    </div>
    <div class="row">
      <div class="col-xs-4 col-xs-offset-4 col-md-2 col-md-offset-5">
        <div class="bgWhite text-center tempFontSize">
          <div class="weatherIcon inlineBlock"><i class="wi"></i>&nbsp;&nbsp;
          </div>
          <div id="tempValue" class="tempValueStyle inlineBlock"></div>
          <div class="tempValueStyle inlineBlock">&deg;</div>
          <div class="tempButton inlineBlock">
            <div class="c selectedTemp inlineBlock">C</div>
            <span>/</span>
            <div class="f inlineBlock">F</div>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div id="summary" class="col-xs-4 col-xs-offset-1 col-md-4 col-md-offset-1 bgWhite weather">Summary loading</div>
      <div id="forecast" class="col-xs-5 col-xs-offset-1 col-md-5 col-md-offset-1 bgWhite weather">Forecast loading</div>
      </div>
    </div>
  </div>
</BODY>

</HTML>
              
            
!

CSS

              
                html,body{
	font-size: 20px;
}
body {
 background:  url(https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg) no-repeat center center;
  background-size: cover;
}
.weather{
	font-size: 150%;
	/* margin: 0 auto; */
  text-align: center;
}
.weatherFont {
  font-family: 'Pattaya', sans-serif;
}
h1 {
	font-size: 170%;
	font-weight: bold;
  color: orange;
	margin:0 0 40px;
	text-shadow: 5px 5px 6px #000;
  text-align: center;
}
.bgWhite{
  background-color: white;
	background-color: rgba(255, 255, 255, .7);
	border-radius: 10px;
	box-shadow: 4px 4px 11px #000;
	margin-bottom: 20px;
	padding: 10px 0;
}
/* Temperature and icon CSS */
.weatherIcon{
	margin-top: 10px;
}
.tempFontSize{
	font-size: 200%;
}
.tempButton{
	cursor: pointer;
	color: #949494;
}
.selectedTemp{
	color: #000;
}
.tempValueStyle{
	color: #000;
  font-size: 150%;
}
.wi{
	font-size: 150%;
	color: #0991e7;
}
.inlineBlock{
	display: inline-block;
}


              
            
!

JS

              
                var tempF = 0;
var tempC = 0;

// First execution by code
$(document).ready(function() {
  navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);
});

// These are needed to get the lat/lon
var locationOptions = {
  enableHighAccuracy: false,
  timeout: 5000,
  maximumAge: 0
};

// Set up function chains to pass 
// the lat/lon to
function locationSuccess(pos) {

  var latitude = pos.coords.latitude;
  var longitude = pos.coords.longitude;
  //For testing:
  //latitude = -43.53;
  //longitude = 172.64;

  // As we cannot use Openweather and api.forecast.io
  // does not offer location names, we need to get
  // this information from google. It does not need to be
  // in the downstream callback chain (set up as a separate callback thread)
  $.getJSON("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude, function(place) {
    var location = place.results[1].formatted_address;
    $("#geolocationText").html(location);  
  });

  getWeather(latitude, longitude);
}

function locationError(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
}

// We have the lat/lon, now we need the
// weather for that location
// Openweather does not work with SSL AJAX for a free
// account so will not work with codepen.io
// so we use api.forecast.io instead so Chrome does not break.
function getWeather(lat, lon) {
  var weatherURL = "https://api.forecast.io/forecast/6a7aefe0e27f5fa46c2a92b7205b2cc9/";
  weatherURL += lat + "," + lon + "?callback=?";
  $.getJSON(weatherURL, processWeather);
}

function changeTempValue() {
  if ($(".c").is(".selectedTemp")) {
    $("#tempValue").html(tempC);
  } else {
    $("#tempValue").html(tempF);
  }
}

// We have the weather data, now display it
function processWeather(data) {
  $("#summary").html("Currently: " + data.currently.summary);
  $("#forecast").html("Forecast: " + data.hourly.summary);
  var icon = data.currently.icon;
  $(".weatherIcon i").addClass("wi-forecast-io-" + icon);
  generateBackgroundImage(data.currently.icon);
  tempF = Math.round(data.currently.temperature);
  tempC = Math.round((data.currently.temperature - 32.0) * 5.0 / 9.0);
  changeTempValue();
  $(".tempButton").on("click", function() {
    $(".c").toggleClass("selectedTemp");
    $(".f").toggleClass("selectedTemp");
    changeTempValue();
  });
}

// We change the background image depending on the 
// type of weather and whether day or night.
function generateBackgroundImage(icon) {
  var image;
  if (icon.includes("cloudy") && icon.includes("night"))
  image = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Moon_Monster2.jpg/1280px-Moon_Monster2.jpg";
  else if (icon.includes("cloudy"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Cumulus_humilis_clouds.jpg/1280px-Cumulus_humilis_clouds.jpg";
  else if ((icon.includes("storm") || icon.includes("lightning")) && icon.includes("night"))
    image = "https://upload.wikimedia.org/wikipedia/commons/a/af/Darwin_1824.jpg";
  else if ((icon.includes("storm") || icon.includes("lightning")))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Desert_Electric.jpg/1280px-Desert_Electric.jpg";
  else if (icon.includes("rain") && icon.includes("wind"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/FEMA_-_37209_-_Windy_wet_weather_in_Texas_following_Hurricane_Dolly.jpg/1280px-FEMA_-_37209_-_Windy_wet_weather_in_Texas_following_Hurricane_Dolly.jpg";
  else if (icon.includes("snow") && icon.includes("night"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Golden_Night_Snow.jpg/1280px-Golden_Night_Snow.jpg";
  else if (icon.includes("snow"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Snowstorm.jpg/1280px-Snowstorm.jpg";
  else if ((icon.includes("rain") || icon.includes("sleet")) && icon.includes("night"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/A_Rainy_Night.jpg/1280px-A_Rainy_Night.jpg";
  else if (icon.includes("rain") || icon.includes("sleet"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Pluie_Alsacienne.JPG/1280px-Pluie_Alsacienne.JPG";
  else if (icon.includes("hurricane") && icon.includes("night"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/ISS-45_Hurricane_Joaquin_night_view.jpg/1280px-ISS-45_Hurricane_Joaquin_night_view.jpg";
  else if (icon.includes("hurricane"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Cyclone_Catarina_from_the_ISS_on_March_26_2004.JPG/1280px-Cyclone_Catarina_from_the_ISS_on_March_26_2004.JPG";
  else if (icon.includes("tornado"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/Tornado0_-_NOAA.jpg/1280px-Tornado0_-_NOAA.jpg";
  else if (icon.includes("hail"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Hailstorm.jpg/1280px-Hailstorm.jpg";
  else if (icon.includes("night") || icon.includes("moon"))
    image = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/A_view_from_above_%28292128510%29.jpg/1280px-A_view_from_above_%28292128510%29.jpg";
  else
      image = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Hopetoun_house_sunny_day.jpg/1280px-Hopetoun_house_sunny_day.jpg";

  image = "url(" + image + ")";
  $("body").css("background-image", image);
}
              
            
!
999px

Console