Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

              
                <body id="body" class="storm">
<div class="main">
		<div class="container">
			<div class="app col-12">
				<h1 class="headline"><span class="location"></span></h1>
				
				<div class="flex-row ">
          <div class="col">
					
						<div class="weather-info">
							<div class="weather-info-animation">
							<canvas id="animated-icon" width="220" height="220"></canvas>
						</div>
						
            </div>
          </div>
				
				
				<div class="col">
					
						<div class="weather-info-text d-flex flex-wrap">
							<div class="col-6">
								<span class="local-time">~~:~~</span>
							</div>
							<div class="col-6">
								<div class="temperature">
									<span class="temp-celsius">°C</span>
									<span class="temp-fahrenheit hidden">°F</span>
                  
								</div> 
							</div>
							<div class="col">
								<span class="weather-condition">~~~</span>
							</div>							
						</div>
					</div>
						
            </div>
						
				<div class="row">
					<div class="search-weather col-8 ">
						<h3>Find a Forecast</h3>
						<form class="form-group" id="my-form" action="">
							<input type="search" placeholder="Search by location or keyword" class="find-forcast form-control">
							<button class="btn ">Search</button>
						</form>
					</div>
				</div>
			
				<div class="row">
					<div class="footer">
						
					</div>
				</div>			


			</div>  
		</div> 
	</div> 
  </body>
              
            
!

CSS

              
                

body {
  background-color: #0F5474;
  color: #FFFAFF; 
  position: relative;
  }

.main {
   height: 100vh;
  
}



.main:before {
  content: "";
  background-color: rgba(0,0,0,.4);
  position: absolute;
  width: 100%;
  height: 100%;
  
}

.headline {
  text-align: center;
  
  padding: 1em 30px;
  font-weight: 700;
  font-family: 'Roboto', sans-serif;
}

.weather-info {
  text-align: center; 
}

.animated-icon {
  width: 200px;
  height: 200px;
  margin-bottom: 2em; 

}

.weather-info-text {
  text-align: center;
  font-size: 2.5em;
  font-family: 'Poppins', sans-serif;
  margin-top: .4em;
  }

.temp-celsius, .temp-fahrenheit {
  cursor: pointer;
  background-color: #666666;
  border-radius: .3em;
  padding:.2rem .4rem ;
}

.temp-celsius:hover, .temp-fahrenheit:hover {
  background-color: #333333;
}

.search-weather {
  background-color: #006885;
  color: #333;
  text-align: left;
  margin:auto;
  margin-top: 1em;
  padding: 5px 15px;
  bottom: 0;
border-radius: 5px}

.search-weather h3 {
  text-align: center;
  color: #FFB300;
  font-weight: 700; }

form {
  margin-bottom: 0; }

input[type="search"] {
  width: 100%; }

button.btn {
  
  margin-top: 1em;
  background-color: #FF2300;
  color: #FFB300; }

button:hover {
  background-color: #A41600;
  color: #B0CF00; }

.attribution {
  background-color: #fff; }

.footer {
  padding-top: 40px;
  text-align: center; }

.footer p {
  margin-bottom: 0.5em;
  color: #fff; }

.footer a {
  color: #B0CF00; 
  text-decoration: none;
}

.hidden {
  display: none;
}

.rain {
  background:  url('https://images.unsplash.com/photo-1486016006115-74a41448aea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1347&q=80') center center;
  background-size: cover; 
}

.clear-day {
   background:  url('https://images.unsplash.com/uploads/141247613151541c06062/c15fb37d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80') center center;
  background-size: cover; 
}

.clear-night {
  background:  url('https://images.unsplash.com/photo-1484950763426-56b5bf172dbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80') center center;
  background-size: cover; 
}

.cloud-day {
  background:  url('https://images.unsplash.com/photo-1528157509193-8254fac59543?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80') center center;
  background-size: cover; 
}

.cloud-night {
  background:  url('https://images.unsplash.com/photo-1510650499-08d11de6119e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80') center center;
  background-size: cover; 
}

.storm {
  background:  url('https://images.unsplash.com/photo-1564343921985-91ced954364a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80') center center;
  background-size: cover;
}

.snow {
  background:  url('https://images.unsplash.com/photo-1547754980-3df97fed72a8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80') center center;
  background-size: cover;
}




              
            
!

JS

              
                // inspired by the Design and code by Ayo Isaiah

//Skycons

let skycons = new Skycons({ color: "#fff4ff" });

skycons.add("animated-icon", Skycons.CLEAR_DAY);

skycons.play();

//Some Global variables

var longitude, latitude, timeHour, timeFull;

//Function to update weather information

function updateWeather(json) {
  longitude = json.coord.lon;
  latitude = json.coord.lat;
  //AJAX request

  let geoJSON = $.getJSON(
    "https://secure.geonames.org/timezoneJSON?lat=" +
      latitude +
      "&lng=" +
      longitude +
      "&username=ayoisaiah"
  ).then(function(timezone) {
    var rawTimeZone = JSON.stringify(timezone);

    var parsedTimeZone = JSON.parse(rawTimeZone);
    var dateTime = parsedTimeZone.time;
    timeFull = dateTime.substr(11);
    $(".local-time").html(timeFull); //Update local time
    timeHour = dateTime.substr(-5, 2);

    //Update Weather parameters and location

    $(".weather-condition").html(json.weather[0].description);
    var temp = [
      (json.main.temp - 273.15).toFixed(0) + "°C",
      (1.8 * (json.main.temp - 273.15) + 32).toFixed(0) + "°F"
    ];
    $(".temp-celsius").html(temp[0]);
    $(".temp-fahrenheit").html(temp[1]);
    
    $(".location").html(json.name);

    //Update Weather animation based on the returned weather description

    var weather = json.weather[0].description;

    if (weather.indexOf("rain") >= 0) {
      skycons.set("animated-icon", Skycons.RAIN);
      document.getElementById("body").className = "rain";
    } else if (weather.indexOf("sunny") >= 0) {
      skycons.set("animated-icon", Skycons.CLEAR_DAY);
      document.getElementById("body").className = "clear-day";
    } else if (weather.indexOf("clear") >= 0) {
      if (timeHour >= 7 && timeHour < 20) {
        skycons.set("animated-icon", Skycons.CLEAR_DAY);
        document.getElementById("body").className = "clear-day";
      } else {
        skycons.set("animated-icon", Skycons.CLEAR_NIGHT);
        document.getElementById("body").className = "clear-night";
      }
    } else if (weather.indexOf("cloud") >= 0) {
      if (timeHour >= 7 && timeHour < 20) {
        skycons.set("animated-icon", Skycons.PARTLY_CLOUDY_DAY);
        document.getElementById("body").className = "cloud-day";
      } else {
        skycons.set("animated-icon", Skycons.PARTLY_CLOUDY_NIGHT);
        document.getElementById("body").className = "cloud-night";
      }
    } else if (weather.indexOf("thunderstorm") >= 0) {
      skycons.set("animated-icon", Skycons.SLEET);
      document.getElementById("body").className = "storm";
    } else if (weather.indexOf("snow") >= 0) {
      skycons.set("animated-icon", Skycons.SNOW);
      document.getElementById("body").className = "snow";
    }
  });
  
}

$(".temperature").click(function() {
      $(".temp-celsius").toggle();
      $(".temp-fahrenheit").toggle();
    });
//Check for Geoloaction support

if (navigator.geolocation) {
  //Return the user's longitude and latitude on page load using HTML5 geolocation API

  window.onload = function() {
    var currentPosition;
    function getCurrentLocation(position) {
      currentPosition = position;
      latitude = currentPosition.coords.latitude;
      longitude = currentPosition.coords.longitude;

      //AJAX request

      $.getJSON(
        "https://api.openweathermap.org/data/2.5/weather?lat=" +
          latitude +
          "&lon=" +
          longitude +
          "&APPID=4e5a45260e98e770e7377f516bc22d75",
        function(data) {
          var rawJson = JSON.stringify(data);
          var json = JSON.parse(rawJson);
          updateWeather(json); //Update Weather parameters
        }
      );
    }

    navigator.geolocation.getCurrentPosition(getCurrentLocation);
  };

  //Find a Forcast

  $("form").on("submit", function(event) {
    event.preventDefault();
    var city = $(".find-forcast").val(); //Get value from form input
    document.getElementById("my-form").reset();

    //AJAX Request

    $.getJSON(
      "https://api.openweathermap.org/data/2.5/weather?q=" +
        city +
        "&APPID=4e5a45260e98e770e7377f516bc22d75",
      function(data) {
        var rawJson = JSON.stringify(data);
        var json = JSON.parse(rawJson);

        updateWeather(json); //Update Weather parameters
      }
    );
  });
} else {
  //If Geolocation is not supported by the browser, alert the user

  alert(
    "Geolocation is not supported by your browser, download the latest Chrome or Firefox to use this app"
  );
}

              
            
!
999px

Console