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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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

            
              <html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=divice-width, initial-scale=1.0">
  <link href="https://fonts.googleapis.com/css?family=Ubuntu|Work+Sans:400,700" rel="stylesheet">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
    crossorigin="anonymous">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons-wind.min.css">
  <link rel="stylesheet" href="style.css">

  <title>Local Weather</title>
</head>

<body>
  <div class="bg">
			<div class="container">
				<div class="row">
					<h1 class="text-center">Local Weather
						<br>Report
					</h1>
				</div>
				<div class="row text-center">
					<div class="border col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 col-xs-offset-1 col-xs-10">
						<div class="row" id="location"></div>
						<p class="hor-line"></p>
						<div class="row">
							<div class="col-xs-6 col-ms-6 text-center">
								<div id="date"></div>
							</div>
							<div class="col-xs-6 col-ms-6 text-center">
								<div id="time"></div>
							</div>
						</div>
						<p id="description"></p>
						<div class="row">
							<div class="col-xs-6 col-ms-6 text-center temp">
								<div id="icon"></div>
							</div>
							<div class="col-xs-6 col-ms-6 text-center temp">
								<div><span id="temp"></span><span class="temp_unit"></span></div>
							</div>
						</div>
						<p class="hor-line"></p>
						<div class="row">
							<div class="col-xs-6 col-ms-6 text-center border-right">
								<div class="text-left"><span><i class="wi wi-strong-wind"></i> Wind: </span><span id="wind"></span></div>
								<div class="text-left"><span><i class="wi wi-windy"></i> Direction: </span><span id="wind_dir"></span></span></div>
							</div>
							<div class="col-xs-6 col-ms-6 text-center">
								<div class="text-left"><span><i class="wi wi-thermometer"></i> Max: </span><span id="temp_max"></span><span class="temp_unit"></span></div>
								<div class="text-left"><span><i class="wi wi-thermometer-exterior"></i> Min: &nbsp;</span><span id="temp_min"></span><span class="temp_unit"></span></div>
							</div>
						</div>
						<p class="hor-line"></p>

						<div class="row">
							<div class="col-xs-6 col-ms-6 text-center border-right">
								<div class="text-left">
									<span><i class="wi wi-humidity"></i> Humidity: </span>
									<span id="humidity"></span>
								</div>
								<div class="text-left">
									<span><i class="wi wi-barometer"></i> Pressure: </span>
									<span id="pressure"></span>
								</div>
							</div>
							<div class="col-xs-6 col-ms-6 text-center">
								<div class="text-left">
									<i class="wi wi-sunrise"></i> Sunrise: <span id="sunrise"></span>
								</div>
								<div class="text-left">
									<i class="wi wi-sunset"></i> Sunset: &nbsp;<span id="sunset"></span>
								</div>
							</div>
						</div>
						<p class="hor-line"></p>
						<div class="row">
							<div class="col-xs-6 col-ms-6 text-center border-right">
								<div class="text-left">
									<span>temp in </span>
									<span><button class="settings settings_selected" id="far">F</button></span>
									<span> / </span>
									<span><button class="settings" id="cel">C</button></span>
								</div>
							</div>
							<div class="col-xs-6 col-ms-6 text-center">
								<div class="text-left">
									<span><button class="settings settings_selected" id="twelve">12</button></span>
									<span> / </span>
									<span><button class="settings" id="twentyfour">24</button></span>
									<span>hours</span>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
    crossorigin="anonymous"></script>
  <script src="js.js"></script>
</body>

</html>
            
          
!

CSS

            
              body, html {
  height: 100%;
  font-family: 'Work Sans', sans-serif;
  color: #eff1f4;
  font-weight: 400;
  overflow: hidden;
}

.bg {
  background-image: url('https://images.unsplash.com/photo-1468413253725-0d5181091126');
  height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: white;
}

.container {
  min-width: 500px;
}

h1 {
  margin-top: 25%;
  margin-bottom: 50px;
  padding: 50px;
  font-size: 6em;
  font-weight: 300;
/*   border: 2px solid red; */
}

a:hover {
  text-decoration: none;
  cursor: pointer;
}

.border {
  border: 2px solid #FFFFFF;
  padding: 1em;
  background-color: rgba(0, 0, 0, 0.7);
}

.border-right {
  border-right: 1px solid #FFFFFF;
}

.hor-line {
  margin-top:10px;
  color: white;
  border-bottom: 1px solid white;
}

.temp {
  font-size: 3em;
}

.text-left {
  padding-left: 20px;
}

.settings {
  border: none;
  border-radius: 50%;
  height: 1.5em;
  width: 1.5em;
  text-align: center;
  text-decoration: none;
  background: none;
  cursor: pointer;
  padding: 0px;
}

.settings_selected {
  border: 1px white solid;
  border-radius: 50%;
}

button:focus {
  outline:0;
}

 /* Media Queries */
/* For mobile devices */
@media only screen and (max-width: 400px) {
  h1 {
    font-size: 2em;
  }
  p {
    font-size: 1.6em;
  }
}
            
          
!

JS

            
              $(document).ready(function () {
  var lat = 0, lon = 0, city = '', 
      tempC = [], // temp[0]=main, temp[1]=max, temp[2]=min
      tempF = [], // temp[0]=main, temp[1]=max, temp[2]=min
      wind = [], // wind[0]=mph, wind[1]=kmh
      time = [], // time[0]=12, time[1]=24
      sunrise = [], // sunrise[0]=12, sunrise[1]=24
      sunset = []; // sunset[0]=12, sunset[1]=24
  
  $.getJSON("https://ipapi.co/json", function (data) {
    lat = data.latitude;
    lon = data.longitude;
    city = data.city;
    state = data.region;
    $("#location").html(city + ", " + state);
    getWeather(lat, lon);
  });

  function getWeather(lat, lon) {
    var url = "";
    var openWeatherURL = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=Imperial" + "&APPID=" + apiKey ;
    var fccWeatherURL = "https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + lon;

    $.getJSON(openWeatherURL).then(function (weatherData) {
      setWeatherData(weatherData); 

      $("#time").text(time[0]);
      $("#date").html(dateConverter(weatherData.dt));

      $("#description").html(weatherData.weather[0].main);
      $("#icon").html(getWeatherIcon(weatherData.weather[0].icon));
      
      $("#temp").html(tempF[0]);
      $("#temp_max").html(tempF[1]);
      $("#temp_min").html(tempF[2]);

      $("#sunrise").text(sunrise[0]);
      $("#sunset").text(sunset[0]);
      
      $("#humidity").text(weatherData.main.humidity + ' %');
      $("#pressure").text(weatherData.main.pressure);
      
      $("#wind").text(wind[0]);
      $("#wind_dir").html(getWindDirection(weatherData.wind.deg));

      $("#far").prop("disabled", true);
    });
  }

  function setWeatherData(weatherData) {
    tempC[0] = Math.round(convertToC(weatherData.main.temp)) + "&#176 C";
    tempC[1] = Math.round(convertToC(weatherData.main.temp_max)) + "&#176 C";
    tempC[2] = Math.round(convertToC(weatherData.main.temp_min)) + "&#176 C";
    tempF[0] = Math.round(weatherData.main.temp) + "&#176 F";
    tempF[1] = Math.round(weatherData.main.temp_max) + "&#176 F";
    tempF[2] = Math.round(weatherData.main.temp_min) + "&#176 F";

    wind[0] = Math.round(weatherData.wind.speed) + " mi/h";
    wind[1] = Math.round(convertToKmph(weatherData.wind.speed)) + " km/h";

    time[0] = timeConverter12(weatherData.dt);
    time[1] = timeConverter24(weatherData.dt);

    sunrise[0] = timeConverter12(weatherData.sys.sunrise);
    sunrise[1] = timeConverter24(weatherData.sys.sunrise);

    sunset[0] = timeConverter12(weatherData.sys.sunset);
    sunset[1] = timeConverter24(weatherData.sys.sunset);
  }

  $("#cel").on("click", function (event) {
    event.preventDefault();
    $("#temp").html(tempC[0]);
    $("#temp_max").html(tempC[1]);
    $("#temp_min").html(tempC[2]);
    
    $("#wind").text(wind[1]);

    $("#cel").prop("disabled", true).addClass("settings_selected");
    $("#far").prop("disabled", false).removeClass("settings_selected");
  });

  $("#far").on("click", function (event) {
    event.preventDefault();
    
    $("#temp").html(tempF[0]);
    $("#temp_max").html(tempF[1]);
    $("#temp_min").html(tempF[2]);
    $("#wind").text(wind[0]);

    $("#far").prop("disabled", true).addClass("settings_selected");
    $("#cel").prop("disabled", false).removeClass("settings_selected");
  });

  $("#twelve").on("click", function (event) {
    event.preventDefault();
    $("#time").text(time[0]);
    $("#sunrise").text(sunrise[0]);
    $("#sunset").text(sunset[0]);
    
    $("#twelve").prop("disabled", true).addClass("settings_selected");
    $("#twentyfour").prop("disabled", false).removeClass("settings_selected");
  });
  
  $("#twentyfour").on("click", function (event) {
    event.preventDefault();
    $("#time").text(time[1]);
    $("#sunrise").text(sunrise[1]);
    $("#sunset").text(sunset[1]);
    $("#twentyfour").prop("disabled", true).addClass("settings_selected");
    $("#twelve").prop("disabled", false).removeClass("settings_selected");
  });

  function getWeatherIcon(id){
    switch(id){
      case "01d":
        return "<i class='wi wi-day-sunny'></i>";
        break;
      case "01n":
        return "<i class='wi wi-night-clear'></i>";
        break;
      case "02d":
        return "<i class='wi wi-day-cloudy'></i>";
        break;
      case "02n":
        return"<i class='wi wi-night-alt-cloudy'></i>";
        break;
      case "03d":
        return "<i class='wi wi-day-cloudy'></i>";
        break;
      case "03n":
        return "<i class='wi wi-night-alt-cloudy'></i>";
        break;
      case "04d":
        return "<i class='wi wi-day-cloudy'></i>";
        break;
      case "04n":
        return "<i class='wi wi-night-alt-cloudy'></i>";
        break;
      case "09d":
        return "<i class='wi wi-day-showers'></i>";
        break;
      case "09n":
        return "<i class='wi wi-night-alt-showers'></i>";
        break;
      case "10d":
        return "<i class='wi wi-day-rain'></i>";
        break;
      case "10n":
        return "<i class='wi wi-night-alt-rain'></i>";
        break;
      case "11d":
        return "<i class='wi wi-day-thunderstorm'></i>";
        break;
      case "11n":
        return "<i class='wi wi-night-alt-thunderstorm'></i>";
        break;
      case "13d":
        return "<i class='wi wi-day-snow'></i>";
        break;
      case "13n":
        return "<i class='wi wi-night-alt-snow'></i>";
        break;
      case "50d":
       return "<i class='wi wi-day-fog'></i>";
        break;
      case "50n":
        return "<i class='wi wi-night-fog'></i>";
        break;
      default:
        return "<i class='wi wi-day-clear'></i>";
    }
  }

  function getWindDirection(deg) {
    if (deg == 0 || deg == 360)
      return "<i class='wi wi-wind towards-0-deg'></i> N";
    else if (deg > 0 && deg < 45)
      return "<i class='wi wi-wind towards-23-deg'></i> NNE";
    else if (deg == 45)
      return "<i class='wi wi-wind towards-45-deg'></i> NE";
    else if (deg > 45 && deg < 90)
      return "<i class='wi wi-wind towards-68-deg'></i> ENE";
    else if (deg == 90)
      return "<i class='wi wi-wind towards-90-deg'></i> E";
    else if (deg > 90 && deg < 135)
      return "<i class='wi wi-wind towards-113-deg'></i> ESE";
    else if (deg == 135)
      return "<i class='wi wi-wind towards-135-deg'></i> SE";
    else if (deg > 135 && deg < 180)
      return "<i class='wi wi-wind towards-158-deg'></i> SSE";
    else if (deg == 180)
      return "<i class='wi wi-wind towards-180-deg'></i> S";
    else if (deg > 180 && deg < 225)
      return "<i class='wi wi-wind towards-203-deg'></i> SSW";
    else if (deg == 225)
      return "<i class='wi wi-wind towards-225-deg'></i> SW";
    else if (deg > 225 && deg < 270)
      return "<i class='wi wi-wind towards-248-deg'></i> WSW";
    else if (deg == 270)
      return "<i class='wi wi-wind towards-270-deg'></i> W";
    else if (deg > 270 && deg < 315)
      return "<i class='wi wi-wind towards-293-deg'></i> WNW";
    else if (deg == 315)
      return "<i class='wi wi-wind towards-315-deg'></i> NW";
    if (deg > 315 && deg < 360)
      return "<i class='wi wi-wind towards-338-deg'></i> NNW";
  }

  function dateConverter(unix) {
    var a = new Date(unix * 1000);
    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    var date = a.getDate() + ' ' + months[a.getMonth()] + ' ' + a.getFullYear();
    return date;
  }

  function timeConverter12(unix) {
    var date = new Date(unix * 1000);
    function minutes(n) { 
      return (n < 10 ? '0' : '') + n;
    }
    var h = date.getHours();
    return (h%12 || 12) + ':' + minutes(date.getMinutes()) + ' ' + (h < 12 ? 'AM' :'PM');
  }

  function timeConverter24(unix) {
    var date = new Date(unix * 1000);
    return date.toLocaleTimeString('en-US', {hour: '2-digit', minute:'2-digit', hour12: false});
  }

  function convertToF(celsius) {
    return celsius * 9 / 5 + 32;
  }

  function convertToC(fahrenheit) {
    return (fahrenheit - 32) * 5 / 9;
  }

  function convertToMph(km) {
    return parseFloat(km) / 1.609344;
  }

  function convertToKmph(m) {
    return parseFloat(m) * 1.609344;
  }
  var apiKey = "5526d9f78b114e09666772228def5897";
});

            
          
!
999px

Console