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

              
                <head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	<title>Weather API</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	<script src="CallAPI.js"></script>	
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="main.css">
	
</head>
<body>
	<div class="container">
			<div class="row">
				<div class="col-md-12 col-xs-12">
					<h1 class=' text-center'>Check your local weather</h1>
					<h2 class="text-danger text-center">A free project by Khoa Le</h2>
					
					<div class="row">
					<div class="col-md-4 col-xs-4">
						<div class="well text-center ajusted" style="height: 150px;padding-top: " id="CityName">
							
						</div>
					</div>
					<div class="col-md-4 col-xs-4">
						<div class="well text-center" style="height: 150px" >
						<div class="weather-icon">
							<img  id="WeatherIcon" src="" alt="">
						</div>
						<div class="temperature" >
						<p id="Temperature" data-temp="celcius"></p>
						</div>
						</div>
					</div>
					<div class="col-md-4 col-xs-4">
						<div class="well text-center ajusted" style="height: 150px" id="ExtraInfo">
						</div>
					</div>
					</div>
							
			</div>
				</div>
				</div>

</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Pacifico);

div.well.text-center.ajusted{
	padding-top: 15%;
}
.well {
   background-color: rgba(245, 245, 245, 0.4);
}
h1{
	font-family: "Pacifico";
	color: yellow;
}
body {
  background-image: url(http://www.marinarium.com/wp-content/gallery/sunny-day/396357_283473645047262_234962699898357_788751_2035093401_n1.jpg);
  position: relative;
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  font-family: "Pacifico";
  min-height: 100%;
}
html{
	min-height: 100%;
}
/*img {
  width: 100px;
  height: 100px;
}*/
#weatherIcon{
	padding-right: 10%;
}
.col-md-12.col-xs-12{
	padding-top: 15%;
}

              
            
!

JS

              
                // get the location when the document is ready

jQuery(document).ready(function($) {
	getLocation();
});
// Get the location and then get the weather when complete

function getLocation(){
// the position variable has all the location data from ip-api.com
	$.getJSON('http://ip-api.com/json', function(data) {
	getWeather(data);
	});
}

function getWeather(data){
	console.log(data);
 // add the lat and lon to the URL
	var url = 'http://api.openweathermap.org/data/2.5/weather?' + 
            'lat=' + data.lat + '&lon=' + data.lon + 
            '&APPID=fb063f0689099c757d885cb93e0a077c&units=imperial'

  // use getJSON with the URL above to get the weather data and study the JSON in the console to parse it

	$.getJSON(url, function(weatherData) {
		var backgroundImg = [/*0Sunnyday */'https://i.ytimg.com/vi/BQxBh-Oen1w/maxresdefault.jpg',
					/*1Rainnyday */'http://www.hbc333.com/data/out/193/46690808-rainy-day-images.jpg',
					/*2Drizzlerain*/'https://kateshrewsday.files.wordpress.com/2013/03/rain.jpg',
					/* 3Snow*/ 'http://www.mulierchile.com/images/snow/snow-2.jpg',
					/* 4Cloudday*/'http://miriadna.com/desctopwalls/images/max/Day-sky.jpg',
					/* 5Thunderstorm*/'https://aos.iacpublishinglabs.com/question/aq/1400px-788px/thunderstorms-made_fdef5d2957edbe09.jpg?domain=cx.aos.ask.com'];

			console.log(backgroundImg[4]);
			
			var id= weatherData.weather[0].id.toString();
			if(id>800 && id<805){
		$('body').css("background-image", 'url(' + backgroundImg[4] + ')');
		} else if(id>599 && id<623){
			$('body').css("background-image", 'url(' + backgroundImg[3] + ')');
		} else if(id>499 && id<532){
			$('body').css("background-image", 'url(' + backgroundImg[1] + ')');
		} else if(id>299 && id<322){
			$('body').css("background-image", 'url(' + backgroundImg[2] + ')');
		} else if(id>199 && id<233){
			$('body').css("background-image", 'url(' + backgroundImg[5] + ')');
		} else {
			$('body').css("background-image", 'url(' + backgroundImg[0] + ')');
		}
	

    // Basic example of showing the temperature in the location

    // Return the weather description in title case
    var weather= weatherData.weather[0].description;
    var weatherSplit = weather.split(" ");
    for (var i=0; i<weatherSplit.length; i++){
    weatherSplit[i]= weatherSplit[i].charAt(0).toUpperCase() + weatherSplit[i].slice(1).toLowerCase();	
    }
    Weather =  weatherSplit.join(" ");
    //
   var CelciusDegree = "<br>" + Weather + "<br>" +Math.ceil((weatherData.main.temp -32) *5/9)  + '&deg' +'C';
   var FarenheitDegree = "<br>" + Weather + "<br>" + weatherData.main.temp + ' &deg' +'F';
  
   var Degree = document.querySelector('#Temperature');
   Degree.setAttribute("data-temp", "celcius");
    Degree.addEventListener('click', function(e) {
      var temp = Temperature.getAttribute("data-temp");
      switch(temp) {
        case "celcius":
          Degree.innerHTML = FarenheitDegree.toString();
          Degree.setAttribute("data-temp", "farenheit");
          break;
        case "farenheit":
          Degree.innerHTML = CelciusDegree.toString();
          Degree.setAttribute("data-temp", "celcius");
          break;
        default:
      }
  });

	$('#CityName').append('City you are living'+ "<br>"+ data.city + ",  " +data.country );
	$('#Temperature').append(CelciusDegree);
	$('#WeatherIcon').attr('src', "http://openweathermap.org/img/w/"+ weatherData.weather[0].icon + ".png");
	$('#ExtraInfo').append('Wind speed: ' + weatherData.wind.speed +" m/h" + "<br>" + "Humidity: " + weatherData.main.humidity + " %");
 });


}



	

              
            
!
999px

Console