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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <html lang="en">

<head>
  <meta charset="utf-8">

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

<body class="full">
  
<div class="wrapper">
  <div class="container">
    <div class="header"><h1></h1></div>
    <div class="weatherbox">
      <div class="locationbox">
        <div class="locactioninfobox">
      <div class="cityarea">
      <h2 id="cityname"></h2>
      </div>
      <div class="countryarea">
        <h3 id="state"></h3>
        <h3 id="country"></h3>
      </div>
        </div>
      <div class="dropdownlocation">
        <div class="dropdown">
        <span tabindex="0" onclick="return true"><i class="fa fa-globe" aria-hidden="true"></i><i class="fa fa-caret-down" aria-hidden="true"></i></span>
        <div tabindex="0" onclick="return true"></div>
    <ul id="testMenu">
        <li onclick="getLocation();"><a href="#">Current Location</a></li>
        <li class="divider"></li>
        <li class="dropdown-header">Main Cities</li>
    </ul>
      </div>
        </div>
      </div>
      <div class="mainline"><hr></div>
    <div class="temperaturearea">
      <div class="toptempbox">
        <div class="tempbox">
      <span id="temp"></span>
        </div>
        <div class="wconditionsbox">
          <span id="wparameter"></span>
      <span id="wdescription"></span>
        </div>
      </div>
      <div class="weather main-toggle"> <!-- Begin Unit Switch -->
      <span>F</span>
      <button id="unit-switch"><span id="unit-toggle"></span></button>
      <span>C</span>
    </div>
    </div>
    </div>
  </div>
</div>
  
  </body>

</html>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto:300,400');
body {
  position: relative;
}
html, body{
  height:100%;
  margin: 0;
}
.wrapper {
  width: 100%;
  height: 100%;
  position: relative;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  background-repeat: no-repeat;
    background-size: cover;
  background-position: center center;
}
.container {
  position: relative;
  display: block;
  margin: 0 auto;
  width: 35%;
  min-width: 300px;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 3px;
  border: 2px solid #009688;
  /*padding: 10px 20px;*/
  box-shadow: 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12), 0 5px 5px -3px rgba(0,0,0,.2);
}
.header h1 {
  text-align: center;
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
  margin: 0 0 10px 0;
  color: #000000;
}
.weatherbox {
  text-align: center;
}
.locationbox {
  position: relative;
   display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content:         center;
  -webkit-justify-content: space-between;
  justify-content:         space-between;
  padding: 10px 20px 0px;
}
.locactioninfobox {
  /* -webkit-flex-basis: 350px;
  flex-basis:         350px;*/
  text-align: left;
}
.cityarea h2 {
  color: #000000;
  font-family: 'Roboto', sans-serif;
  font-weight: normal;
  font-size: 2em;
  margin: 0;
}
.countryarea {
  position: relative;
   display: -webkit-flex;
  display: flex;
  /*-webkit-justify-content: center;
  justify-content:         center;*/
  margin: 0 auto;
  text-align: left;
}
.countryarea h3 {
  margin: 0 0 10px 0;
  font-family: 'Roboto', sans-serif;
  font-weight: normal;
  color: #000000;
}
.countryarea h3:first-child {
  margin-right: 8px;
}
.dropdownlocation {
  -webkit-align-self: center;
  align-self: center;
}
.dropdown {
  position: relative;
  /*display: inline-block;*/
  font-size: 16px;
  color: #FFF;
}
.dropdown-header {
  display: block;
  padding: 3px 20px;
  font-size: 12px;
  line-height: 1.42857143;
  color: #777;
  white-space: nowrap;
  text-transform: uppercase;
}
.dropdown > span {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.dropdown span {
  box-sizing: border-box;
  /*display: inline-block;*/
  width: 100%;
  background-color: #57A0D4;
  padding: 10px 20px;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  font-size: 20px;
}
.dropdown span .fa {
  display: inline;
}
.dropdown span .fa-globe {
  margin-right: 10px;
}
.dropdown > span,
.dropdown > div {
  cursor: pointer;
  outline: 0;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
.dropdown > div {
  background-color: rgba(0, 0, 0, 0);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
}
.dropdown > span:focus ~ div {
  display: block;
}
.dropdown > ul {
  position: absolute;
  list-style: none;
  text-align: left;
  /*width: 100%;*/
  min-width: 160px;
  z-index: 1;
  visibility: hidden;
  transition: visibility 0.5s;
  opacity: 0;
  padding: 5px 0;
  margin: 2px 0 0;
  font-size: 14px;
  text-align: left;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2);
  /*display: none;*/
  background-color: #fff;
  border: 1px solid #ccc;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 4px;
  -webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
  box-shadow: 0 6px 12px rgba(0,0,0,.175);
}
.dropdown > span:focus ~ ul {
  visibility: visible;
  opacity: 1;
}
ul li{
  /*padding: 15px;*/
  background-color: #fff;
  color: #4FB9A7;
  margin-bottom: 1px;
  cursor: pointer;
}
ul li a {
  padding: 8px 20px;
  color: inherit;
  text-decoration: none;
  display: block;
}
ul li a:hover{
  background-color: #4FB9A7;
  color: #FFF;
}
ul .divider {
  height: 1px;
  margin: 9px 0;
  overflow: hidden;
  background-color: #e5e5e5;
}
.mainline hr {
  border: 0;
  height: 1px;
  background: #000000;
  opacity: 0.2;
}
.temperaturearea {
  padding: 0px 20px 10px;
}
.toptempbox {
  position: relative;
   display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content:         center;
}
.tempbox {
  -webkit-flex-basis: 180px;
  flex-basis:         180px;
}
.temperaturearea span#temp {
  position: relative;
  color: #000000;
  font-family: 'Roboto', sans-serif;
  font-size: 10em;
}
.temperaturearea #temp:after {
    content: '';
    position: absolute;
    height: 10px;
    width: 10px;
    top: 16px;
    right: -17px;
    border: 3px solid #000000;
    border-radius: 50%;
}
.wconditionsbox {
   -webkit-align-self: flex-end;
  align-self: flex-end;
  padding-bottom: 35px;
  padding-left: 5px;
   -webkit-flex-basis: 100px;
  flex-basis:         100px;
}
.wconditionsbox span {
  display: block;
  text-align: left;
}
#wparameter {
  font-size: 3.5em;
}
#wdescription {
  font-size: 1em;
}
#wparameter, #wdescription {
  color: #000000;
  font-family: 'Roboto', sans-serif;
}
.weather > span {
  position: relative;
  font-family: 'Roboto', sans-serif;
  font-size: 1.2rem;
  color: #000000;
}
.weather > span:before {
    content: '';
    position: absolute;
    left: -10px;
    top: 0px;
    height: 3px;
    width: 3px;
    border: 2px solid #000000;
    border-radius: 50%;
}
.main-toggle span {
  margin: 0 0 0 16px;
}
.main-toggle span:last-child {
  margin-left: 11px;
}
.weather button {
		background: #6bbf6b;
		border: none;
		border-radius: 30px;
		outline: none;
		width: 45px;
		height: 20px;
		margin: 5px 5px 0;
		cursor: pointer;
		position: relative;
		transition: background .2s;
}
.weather button:active {
		background: #67b567;
	}
.weather #unit-toggle {
		position: absolute;
		display: inline-block;
		left: -8px;
		top: 2px;
		width: 15px;
		height: 15px;
		background: #fff;
		border-radius: 50%;
		transition: left .2s;
}
#unit-toggle.toggle {
		left: 16px;
}
@media screen and (max-width: 479px) {
   .container {
  width: 85%;
  min-width: 300px;
}
}
@media screen and (min-width: 480px) and (max-width: 900px) {
  .container {
  width: 65%;
  min-width: 300px;
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  //load the functions once the page open
  $(".cityarea").html(getLocation);
  testMenu();
  
});
 
  var currentLat;
  var currentLong;
  var currentCity;
  var currentRegion;
  var currentCountry;
  
  var mainCities = {
    'San_Francisco': {
      'region': 'California',
      'country': "United States",
      'lat': 37.7749300,
      'lon': -122.4194200
    },
    'St._Louis': {
      'region': 'Missouri',
      'country': "United States",
      'lat': 38.6272700,
      'lon': -90.1978900
    },
    'Miami': {
      'region': 'Florida',
      'country': "United States",
      'lat': 25.7742700,
      'lon': -80.1936600
    },
    'Tokyo': {
      'region': 'Tokyo',
      'country': "Japan",
      'lat': 35.689500,
      'lon': 139.6917100
    },
    'Denver': {
      'region': 'Colorado',
      'country': "United States",
      'lat': 39.739100,
      'lon': -104.984700
    }
  };
  
//add the cities from var mainCities to the blue dropdown button
  function testMenu() {
    for (var place in mainCities) {
      var city = place.replace(/_/g, ' ');
      $('#testMenu').append("<li onclick=testWeather('" + place + "');><a href='#'>" + city + "</a></li>");
    }
  };
  
//every click from the cities in the dropdown button call this function. cityLocation get the city from var mainCities
  function testWeather(cityLocation) {
    
    currentLat = mainCities[cityLocation].lat;
    currentLong = mainCities[cityLocation].lon;
    currentRegion = mainCities[cityLocation].region;
    currentCity =cityLocation.replace(/_/g, ' ');
    currentCountry = mainCities[cityLocation].country;
    
    //call the function getWeather and apply the data above to this function
    getWeather();
    
  };
  
//find the current location anywhere by the computer's ip address
//use https://ipapi.co/ instead of http://ip-api.com/json
  function getLocation() {
    $.getJSON('https://ipapi.co/json', function(data) {
      
      currentRegion = data.region;
      //currentCity = data.city;
      currentCountry = data.country;
      currentLat = data.latitude;
      currentLong = data.longitude;
      
      //call the function getWeather and apply the data above to this function
      getWeather();
      
    });
  };
  
//very important function. It collect latitude and longitude of the current location or main city and use it to get the local weather from api Open Weather app. It also have other stuff such as converting between F and C, background images which depends on the weather icons, etc. 
function getWeather() {
  
  $("#state").text(currentRegion);
  $("#country").text(currentCountry);
  
  //use https://fcc-weather-api.glitch.me/api/current? instead of http://api.openweathermap.org/data/2.5/weather?
  $.getJSON('https://fcc-weather-api.glitch.me/api/current?lat=' + currentLat + '&lon=' + currentLong /*+ '&units=imperial&APPID=e656b9ee098cf2341fcfdb365b96b4a8'*/, function(json) {
    
    $("#cityname").text(json.name);
    
    var showfahrenheit = true;
    var temcelcius = Math.round(json.main.temp);
    var tempfahrenheit = Math.round((temcelcius * 9/5) + 32);
    
    
    $("#temp").html(tempfahrenheit);
    
    $('#unit-switch').off('click');
    
    $('#unit-switch').on('click', function() {
      if (showfahrenheit === false) {
        $("#temp").html(tempfahrenheit);
        showfahrenheit = true;
      } else {
        $("#temp").html(temcelcius); 
        showfahrenheit = false;
      }
      
      $("#unit-toggle").toggleClass("toggle");
			
    });
    
     var prefix = "wi wi-owm-";
    var weatherIcons = json.weather[0].id;
    var icon = prefix + weatherIcons;
    
 $("#wparameter").html("<i class='" + icon + "'></i>");   $("#wdescription").text(json.weather[0].description);
   
      var weatherImages = {
  'rain': 'https://res.cloudinary.com/kikibres/image/upload/v1543260894/FCC%20Weather%20Images/rainpic1.jpg', 
  'clear': 'https://res.cloudinary.com/kikibres/image/upload/v1543260896/FCC%20Weather%20Images/clearskypic1.jpg',
    'snow': 'https://res.cloudinary.com/kikibres/image/upload/v1543260899/FCC%20Weather%20Images/snowpic.jpg',
    'clouds': 'https://res.cloudinary.com/kikibres/image/upload/v1543260892/FCC%20Weather%20Images/cloudspic.jpg',
    'fog': 'https://res.cloudinary.com/kikibres/image/upload/v1543260892/FCC%20Weather%20Images/fogpic.jpg',
    'thunder': 'https://res.cloudinary.com/kikibres/image/upload/v1543260896/FCC%20Weather%20Images/thunderstormpic.jpg',
    'windy': 'https://res.cloudinary.com/kikibres/image/upload/v1543260897/FCC%20Weather%20Images/windybreezepic.jpg',
    'dust': 'https://res.cloudinary.com/kikibres/image/upload/v1543260891/FCC%20Weather%20Images/dustsandpic.jpg',
    'tornadostorm': 'https://res.cloudinary.com/kikibres/image/upload/v1543260898/FCC%20Weather%20Images/tornadomistpic.jpg'
};
      
      var imagepic;
      
      if (weatherIcons >= 200 && weatherIcons <= 232 ) {
        imagepic = weatherImages.thunder;
      } else if (weatherIcons >= 300 && weatherIcons <= 531) {
        imagepic = weatherImages.rain;   
      } else if (weatherIcons >= 600 && weatherIcons <= 622) {
        imagepic = weatherImages.snow;
      } else if (weatherIcons >= 701 && weatherIcons <= 731) {
        imagepic = weatherImages.dust;
      } else if (weatherIcons == 741) {
        imagepic = weatherImages.fog;
      } else if (weatherIcons >= 751 && weatherIcons <= 781) {
        imagepic = weatherImages.dust;
      } else if (weatherIcons == 800) {
        imagepic = weatherImages.clear;
      } else if (weatherIcons >= 801 && weatherIcons <= 804) {
        imagepic = weatherImages.clouds;
      } else if (weatherIcons >= 900 && weatherIcons <= 906) {
        imagepic = weatherImages.tornadostorm;
      } else if (weatherIcons >= 951 && weatherIcons <= 962) {
        imagepic = weatherImages.windy;
      } else {}
      
      var speedimg = 500;
    
     $(".wrapper").animate({opacity: 0}, speedimg, function() {
       
       $(".wrapper").animate({opacity: 1}, speedimg);
       $(".wrapper").css(
    'background-image', 'url(' + imagepic + ')');
       
     });
    
  });
};
  
              
            
!
999px

Console