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 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.

Quick-add: + add another resource

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.

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.

            
              <html>
<head>
  <meta charset="UTF-8" />
  <title>Local Weather</title>
</head>
<body>
        <div class="container">
        <h2 id="time" class="text-center"></h2>
        <h2 id="city" class="text-center">Local Weather</h2>
        <div id="circleDiv" class="container text-center">
									<div id="weatherInfo" class="text-center">
										<p id="weather"></p>
										<img id="icon" src="" alt="">
										<p id="fTemp" class="temperature">00.0&#8457</p>
										<br>
										<img id="windIcon" src="https://res.cloudinary.com/serggcloud/image/upload/v1481574861/wind-icon_yyvfdx.png">
										<p id="windSpeed">00.0 mph wind speed</p>
									</div>    
        </div>
									<div id="link">
										<a href="https://codepen.io/serg_92/">by Sergio</a>
									</div>    
        
</body>
</html>
            
          
!
            
              body{
    
    background:url(https://res.cloudinary.com/serggcloud/image/upload/v1478840622/weatherimages/sunny_wbevqd.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
	color: rgba(255, 255, 255, 1);
}
	h1, h2{
  text-align:center;   
}
#circleDiv{
    text-align: center;
    height: 400px; 
    width: 400px; 
    background-color: rgba(28, 28, 28, 0.8);
    border-radius: 100%;
    color: rgba(255, 255, 255, 1);
				font-size:  17px; 

}
#weatherInfo {
    margin-top: 30px;
    padding-top: 25px; 
    text-align: center;
    color: rgba(255, 255, 255, 1);    
}

#city {
    margin-top: 50px; 
    
}
#time{
    margin-top: 50px;
    
}

.temperature{
    font-size: 70px;
    border-bottom: 2px solid white; 
}

#fTemp:hover{
    color: rgba(41, 87, 212, 1);
}

#icon{
	width: 80px; 
	height: auto;
	margin: 0 auto; 
}

#windIcon{
			width:40px; /* you can use % */
    height: auto; 
				padding-bottom: 2px; 
}

#windSpeed{
		margin-top: 0;
}

#link{
    text-align: center; 
}

a{
    text-decoration: none; 
}


            
          
!
            
              

var firstTime = new Date();
var dayHours = firstTime.getHours(); 
console.log(dayHours); 

if (!( (dayHours > 5) && (dayHours < 18) )){
		//it should be night
		//console.log("night");
		$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1478840611/weatherimages/night_rpgsms.jpg)');
}

$.getJSON("https://crossorigin.me/http://ip-api.com/json", function(json){
	console.log("firstJson");
	$(document).ready(function(){

		var lat = json.lat;
		var long = json.lon; 
 	 console.log(lat);
 	 console.log(long); 
		
				//API KEY WITH LAT AND LONG LOCATION
				var apiKey = 'http://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+long+'&appid=ef2473d4b97e37b0097de1f3cf0ff486';

				//USE API TO GET WEATHER DATA
				$.getJSON(apiKey, function(data){
			
					var city = data.name; 
					var kTemp = data.main.temp;  
					var windSpeed = data.wind.speed;
					var weather = data.weather[0].description;
					var icon = data.weather[0].icon; 
					var tempSwap = false; 


					//CONVER WINDSPEED TO MPH
					windSpeed = (2.237 * (windSpeed)).toFixed(1);

					//CONVERT KELVIN TO FARENHEIT AND CELSIUS
					var fTemp = ((kTemp) * (9/5) - 459.97).toFixed(1);
					var cTemp = ((kTemp) - 273).toFixed(1); 


					//GET TIME & DATE
					var time = new Date();

					//CONVERT TIME TO 12HR FORMAT
					function formatAMPM(date) {
						var hours = date.getHours();
						var minutes = date.getMinutes();
						var ampm = hours >= 12 ? 'pm' : 'am';
						hours = hours % 12;
						hours = hours ? hours : 12; // the hour '0' should be '12'
						minutes = minutes < 10 ? '0'+minutes : minutes;
						var strTime = hours + ':' + minutes + ' ' + ampm;
						return strTime;
					}

					// FORMAT DATE INTO MONTH DAY, YEAR 
					var formattedDate = time.toLocaleDateString("en-US",options) +" "+ formatAMPM(time)
					var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };

					// OUPUT COMPLETE DATE & TIME
					var formattedDate = time.toLocaleDateString("en-US",options) + " " + formatAMPM(time);
					//console.log(formattedDate); 

					//CHECK WEATHER TO UPDATE BACKGROUND
					var day = time.getHours(); 

					if (( (day > 5) && (day < 18) )){
						//DAY CHECK ICON
						// console.log("day");
						switch(icon){
							case "50d":
							case "03d":
							case "04d":
								// console.log("cloudy day background");
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001301/cloudyDay_rovfr5.jpg)');
								break;
							case "09d":
							case "10d":
							case "11d":
								// console.log("rainy day background");
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001311/rainyDay_qpm4yw.jpg)');
								break; 
							case "13d":
								// console.log("snowy background");
								//CHANGE BACKGROUND AND FONT COLOR 
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001323/snowDay_lurk7n.jpg)');
								$("body").css('color','rgba(29, 29, 29, 1)');
							default:
								// console.log("no match for icon");
								break; 
								}

					}else if((day >= 18) || (day <= 6)){
						//NIGHT CHECK ICON
						// console.log("night");
						switch(icon){
							case "50n":
							case "03n":
							case "04n":
								// console.log("cloudy night background");
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001306/cloudyNight_ln3ryd.jpg)');
								break;
							case "09n":
							case "10n":
							case "11n":
								// console.log("rainy night background");
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001316/rainyNight_c4pyax.jpg)');
								break; 
							case "13n":
								// console.log("snowy night background");
								$("body").css('background-image','url(https://res.cloudinary.com/serggcloud/image/upload/v1481001326/snowNight_wssl89.jpg)');
							default:
								// console.log("no match for icon");
								break; 
								}
					}else{
						// console.log("Something went wrong");
					}


					//UPDATE HTML CONTENT 
					$("#city").html(city); 
					$("#fTemp").html(fTemp + "&#8457"); 

					$("#fTemp").click(function(){
						if(tempSwap === false){
							$("#fTemp").html(cTemp + "&#8451"); 
							tempSwap = true; 
						}else{
							$("#fTemp").html(fTemp + "&#8457"); 
							tempSwap = false; 
						}
					}); //END UPDATE WITH .CLICK

					$("#windSpeed").html(windSpeed + " mph wind speed"); 
					$("#weather").html(weather);
					$("#icon").attr("src","http://openweathermap.org/img/w/"+icon+".png");
					$("#time").html(formattedDate);

				}); //END OF JSON API KEY  
   });//END OF DOCUMENT READY 
	});//END OF api-api
            
          
!
999px
Loading ..................

Console