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.

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

              
                <div class='text' id='message'>Click the Button to get the Weather !</div>
<div class = button id='clickButton'>
  <div id='pointer'></div>
</div>
<div class = 'main'>
<div class = 'wrapper'>
<div id="weatherBox">
  <div class = 'background'></div>
  <div id='locationbox'>
    <span id='city'></span>
    <img id = "countryimg" src="">
  </div>
  
  <div class= 'container' id="weather">
    <div class = 'background'></div>
        <ul>
          <li>Weather :<span id='meteo'></span></li>
          <li>Wind : <span id='wind'></span> MpH</li>
          <li>Temperature : <span id='temperature'></span> °F</li>
          <li>Pressure : <span id='pressure'></span> mb</li>
          <li>Humidity : <span id='humidity'></span></li>
        </ul>
    </div>
  </div>  
</div>
</div>  
              
            
!

CSS

              
                html,body{
  background: radial-gradient(#153F4B, #0F1540);
  margin : 0;
  height : 100%;
  
}

.text{

  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  border: none;
  position : absolute;
  left : 50%;
  top : 22%;
  transform : translateX(-50%);
  -moz-transform : translateX(-50%);
  -webkit-transform : translateX(-50%);
  -o-transform : translateX(-50%);
  font: 40px "Atomic Age", Helvetica, sans-serif ;
  color: rgb(64, 126, 196);
  text-align: center;
  -o-text-overflow: clip;
  text-overflow: clip;
  text-shadow: 1px 1px 0 rgb(77,162,252) , -1px -1px 0 rgb(77,162,252) , 1px -1px 0 rgb(77,162,252) , -1px 1px 0 rgb(77,162,252) ;
}

.button{
  background-color : rgba(77,162,252,0.2);
  position : absolute;
  top : 50%;
  margin-top : -75px;
  left : 50%;
  margin-left : -75px;
  width : 120px;
  height : 120px;
  border : 5px solid white;
  border-radius : 50%;
  transition : background-color 250ms ease-in-out,
               transform 250ms ease-in-out;
  
}
.button:hover{
  background-color: rgba(255,255,255,0.8);
  transform : scale(1.1);
}

/*.button:hover{
  animation : bigger 600ms ease-in-out 0s forwards
} */

#pointer {
  height : 100%;
  width : 100%;
  background : url('https://image.flaticon.com/icons/svg/69/69434.svg') no-repeat;
  background-size : 80%;
  background-position : center;
}
/*@keyframes bigger {
  100%{
    transform : scale(1.07);
    background-color : rgba(240,240,240,.75);
   
  }
} */

.main {
    height: 100%;
    width: 100%;
    display: table;
}
.wrapper {
    display: table-cell;
    height: 100%;
    vertical-align: middle;
}

#weatherBox{
  border: 8px solid white;
  border-radius : 25%;
  margin : 0 auto;
  width : 750px;
  height : 500px;
 /* position: absolute;
  margin: auto;
  left : 0;
  right : 0;
  top : 0;
  bottom : 0; */
}

#city{
  display:block;
}
.background {
  background-color: rgba(255, 255, 255, 0.5);
  filter : blur(5px);
  border-radius : 40px;
  
}
#weatherBox > .background {
  width : 70%;
  height : 27%;
  margin : 0 auto;
} 
.container > .background {
  height : 100%;
  width : 50%;
  margin-top : 20px;
  margin-left : 25px;
  margin-bottom : -340px;
}
#locationbox{
  margin-top : -130px;
  min-width: 30%;
  text-align : center;
  position: relative;
  z-index : 1;
}
.container {
  height : 60%;
  width : 100%;
}
ul,span {
  list-style : none;
  font-size : 35px;
  position : relative;
  z-index : 1;


}
li {
  padding : 10px;
  }
              
            
!

JS

              
                $(document).ready(function(){
  //$('#weatherBox').hide();
  $("#weatherBox").hide();
  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
  });
  }
  
  //getCountry();
  //GetCity();
  
});

$(".button").on('click',function(){
  
  getCountry();
  getCity();

});
$(document).ajaxStart(function() {
  $("#message").html("Please Wait ... ");  
});
$(document).ajaxStop(function(){
  $('#weatherBox').fadeIn(600);
  setWeather();
  $('#message').hide();
  $('#clickButton').hide();
}); 
  function setWeather(){
  document.getElementById("wind").innerHTML = wind;
 document.getElementById("temperature").innerHTML = temperature;
 document.getElementById("pressure").innerHTML = pressure;
 document.getElementById("humidity").innerHTML = humidity;
 document.getElementById("meteo").innerHTML= weather;
    // getting back img
          
 document.getElementById("weatherBox").style= "background :url(" + imagebank[weather] + ") no-repeat; background-size : cover;";   
    // getting city
 document.getElementById("city").innerHTML = city + " , " + country;
 document.getElementById("countryimg").src = "http://www.geognos.com/api/en/countries/flag/" + countryCode + ".png";
}
    


var imagebank = {
  IWind : 'https://image.flaticon.com/icons/svg/56/56086.svg',
  ITemperature : 'https://d30y9cdsu7xlg0.cloudfront.net/png/218414-200.png',
  IPessure : 'https://d30y9cdsu7xlg0.cloudfront.net/png/1841-200.png',
  IHumidity : 'https://image.flaticon.com/icons/svg/219/219816.svg',
  Drizzle : 'http://pixdaus.com/files/items/pics/9/43/95943_ec26208a9394e79d9e2a50197fff5192_large.jpg',
  Snow : 'http://cdn1.theodysseyonline.com/files/2016/02/08/6359048687053497271327874315_snow-day-5.jpg',
  Clear : 'http://www.sunwindenergy.com/sites/default/files/field/image/solar_thermal_new_york.jpg',
  Rain : 'https://orig00.deviantart.net/aeab/f/2008/293/c/1/rainy_day_by_rhads.jpg',
  Clouds : 'https://static.pexels.com/photos/901/city-clouds-cloudy-sun.jpg',
  Fog : 'https://img00.deviantart.net/6797/i/2013/316/3/a/a_foggy_night_by_m_eralp-d6tz2vb.jpg',
  Mist : 'https://www.metoffice.gov.uk/binaries/content/gallery/mohippo/images/learning/learn-about-the-weather/fog/mist-in-herzel-switzerland.-photo-by-ricardo-gomez-angel.jpg'
}

/*function getbackimg(){
  var background = document.getElementById("background-tile");
  background.style.backgroundImage = "url(http://www.sunwindenergy.com/sites/default/files/field/image/solar_thermal_new_york.jpg)"  
}*/
function getCountry(){
$.ajax({ 
        dataType: "json",
        contentType: "application/json",
        type : "GET",
        url: "https://fcc-weather-api.glitch.me//api/current?",
        data : {
          lat: latitude,
          lon: longitude,      
        }
})
  .done(function(quote){
 temperature = Math.round(2*parseFloat(quote.main.temp))/2;
 wind = quote.wind.speed;
 pressure = quote.main.pressure;
 humidity = quote.main.humidity;
 weather = quote.weather[0].main;
 console.log(temperature)
 country = quote.sys.country;
 /*document.getElementById("wind").innerHTML = wind;
 document.getElementById("temperature").innerHTML = temperature;
 document.getElementById("pressure").innerHTML = pressure;
 document.getElementById("humidity").innerHTML = humidity;
 document.getElementById("meteo").innerHTML= weather;         
  // getting back img
          
 document.getElementById("weatherBox").style= "background :url(" + imagebank[weather] + ") no-repeat; background-size : cover;";      
*/
        })
  .fail(document.getElementById("temperature").innerHTML = "error"); 
  
}
function getCity(){
$.ajax({
  datatype : "json",
  contentType : "application/json",
  type : "GET",
  url : "https://nominatim.openstreetmap.org/reverse?",
  data : {
    format:"json",
    lat :"50.8503",
    lon : "4.3517",
    zoom:"18",
    adressdetails:"1"
  },
  success : function(quote){
     city = quote.address.city;
     country = quote.address.country
     countryCode = quote.address.country_code.toUpperCase()
    
  },
  error : document.getElementById("city").innerHTML = "error!"
});
};


// secret api key





/*var rain = ""
var wind = ""
var time;
$.ajax({
  type : "GET",
  url : "https://fcc-weather-api.glitch.me/api/current?lon=139&lat=35",
  sucess : function(weather){
    windspeed = weather.wind[0];
    rain = weather.rain;
    document.getElementById("weather").innerHTML = weather;
  },
  error:document.getElementById("weather").innerHTML = "error"
}) */
              
            
!
999px

Console