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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <body class="body">
  <div class="header">
    <p>Weather App</p>
  </div>  
  <div class="div1">
    <div class="section1">
      <figure class="icons" id="icons">
      </figure>
    </div>
    <div class="section2">
       <ul>
        <li id="location"></li>
        <li id ="temp"></li>
        <li id ="weather"></li>
        <li id = "tempSymbol"><button class="button">&#x2103</button></li>
        </ul>        
    </div>
  </div>
</body>

            
          
!
            
              /*rain - https://wallpaperscraft.com/image/rain_drops_splashes_heavy_rain_dullness_bad_weather_60638_1366x768.jpg*/
/*cloudy=
http://extrawall.net/images/wallpapers/93_1366x768_cloudy_day_in_seattle.jpg*/
/*haze = https://wallpaperscraft.com/image/wood_fog_haze_cool_dampness_55771_1366x768.jpg*/
body {
  margin: 0;
  padding: 0;
}

.div1 {
  #background-color:rgb(0, 0, 0);
  position: relative;
  width: 100%;
  margin: 150px 0 100px 0;
}

.section1 {
  position: absolute;
  #background-color:blue;
  background-color: rgba(0, 0, 0, 0.4);
  height: 100%;
  left: 0;
  /*change*/
  width: 48%;
  float: left;
  border-radius: 10px;
}

.icons {
  #position:relative;
  #background-color:yellow;
  text-align: right;

  height: 100%;
}
.icons > canvas {
  #position:relative;
  #background-color:green;

  margin-right: 10px;
  #height:100%;
}
.section2 {
  position: relative;
  line-height: 100%;
  #background-color:blue;
  background-color: rgba(0, 0, 0, 0.4);
  #text-align:center;
  width: 50%;
  height: 100%;
  left: 50%;
  #top:40%;
  border-radius: 10px;
}

.section2 > ul {
  #background-color:yellow;
  height: 100%;
  width: 100%;
  padding-left: 10px;
  margin-bottom: 0;
  text-decoration: none;
  list-style: none;
  line-height: 38px;
  font-size: 22px;
  font-family: Rockwell;
  display: inline-block;
  text-align: left;
  color: rgba(255, 255, 255, 1);
  #filter: brightness(0);
}

#weather {
  float: left;
}

.header {
  position: relative;
  background-color: rgba(0, 0, 0, 0.4);
  height: 40px;
  margin-top: 0;
  top: 0;
  text-align: center;
}

.header > p {
  position: absolute;
  #background-color:yellow;
  left: 43%;
  font-size: 25px;
  font-family: Rockwell;
  #filter:brightness(0);
  color: rgba(255, 255, 255, 1);
}

/*.section2{
  line-height:100%;
  background-color:rgba(0,0,0,0.4);
  text-align:center;
  position:absolute;
  width:100%;
  top:40%;
  #opacity:0.5;
  #filter: alpha(opacity=60); #for IE 8 and below
}*/

.button {
  background-color: rgba(0, 0, 0, 0);
  color: rgba(255, 255, 255, 1);
  border-color: rgba(0, 0, 0, 0);
  padding: 0;
  margin: -4px 0 0 0;
  cursor: pointer;
}
.button. {
  background-color: blue;
  transition: all .4s ease-in-out;
  border-color: rgba(0, 0, 0, 0);
}
.button:hover{
  transform: scale(1.3);
  border-color: rgba(0, 0, 0, 0);
}


            
          
!
            
              $(document).ready(function() {
  latitudeAndLongitude().then(makeCorrds).catch(console.error);

  /*optional*/
  /*var canv = document.createElement("canvas");
  canv.id = "clear-day";
  canv.width = 64;
  canv.height = 64;
  document.getElementById("icons").appendChild(canv);*/
  /*document.getElementById("icons").innerHTML = '<canvas id="rain" width=64 height=64></canvas>';
  var icons = new Skycons({"color": "black"});
  icons.set("rain", Skycons.RAIN);
  icons.play();*/
});

//promise based sync function
function latitudeAndLongitude() {
  return new Promise(function(resolve, reject) {
    navigator.geolocation.getCurrentPosition(
      function(position){        
        resolve(position);
      }, function(error){
        reject(error);
        //or reject(new Error('Something went wrong'))
        }
    );
  });
}
/*coordinates here*/
function makeCorrds(position) {
  
  console.log(position);
  latitude = /*51.8186;*/ position.coords.latitude;
  longitude = /*5.0935;*/ position.coords.longitude;
  getLocation(latitude,longitude);
  getWeather(latitude,longitude);
  
}

//function to get weather using FCC weather api return json output
function getWeather(latitude, longitude){
  var weatherSummary;
  var link;
    /*link = "https://api.darksky.net/forecast/c0ff36328ca5f9015b081daa58dd37bb/"+latitude+","+longitude + "?callback=?";// add the call back to make it a jsonp request*/
 
      link = "https://fcc-weather-api.glitch.me/api/current?"+"lat="
    +latitude+"&lon="+longitude +"&callback=?";
     $.getJSON(link,function(data){     
     var html1 = "Weather Summary: "+ data.weather[0].main;
     var html2 = "Temprature: "+ data.main.temp;
     weatherSummary = data.weather[0].main; 
     console.log(weatherSummary);
     $("#temp").text(html1);
     $("#weather").text(html2);  
       
     //weather types - haze,clouds,rain,clear,light intensity drizzle,broken clouds,light rain,drizzle
     var icons = new Skycons({"color": "white"});
     if(weatherSummary.toLowerCase() == 'haze'){
    $(".body").css("background-image",'url("https://wallpaperscraft.com/image/wood_fog_haze_cool_dampness_55771_1366x768.jpg")');
   document.getElementById("icons").innerHTML = '<canvas id="fog" width=100 height=100></canvas>';
   icons.set("fog", Skycons.FOG);
  }else if(weatherSummary.toLowerCase() == 'mist'){
    $(".body").css("background-image",'url("http://www.mrwallpaper.com/wallpapers/early-morning-mist-1366x768.jpg")');
   document.getElementById("icons").innerHTML = '<canvas id="fog" width=100 height=100></canvas>';
   icons.set("fog", Skycons.FOG);
  }else if(weatherSummary.toLowerCase() == 'clouds'){
    $(".body").css("background-image",'url("https://wallpaperscraft.com/image/city_hong_kong_morning_cloudy_69332_1366x768.jpg")');
   document.getElementById("icons").innerHTML = '<canvas id="cloudy" width=100 height=100></canvas>';
  icons.set("cloudy", Skycons.CLOUDY); 
  }else if(weatherSummary.toLowerCase() == 'rain'){
    $(".body").css("background-image",'url("https://wallpaperscraft.com/image/rain_drops_splashes_heavy_rain_dullness_bad_weather_60638_1366x768.jpg")');
  document.getElementById("icons").innerHTML = '<canvas id="rain" width=100 height=100></canvas>';
   icons.set("rain", Skycons.RAIN); 
  }else if(weatherSummary.toLowerCase() == 'clear'){
    $(".body").css("background-image",'url("https://s-media-cache-ak0.pinimg.com/originals/7a/c9/37/7ac93782adf2998d1713c3ca98385c65.jpg")');
  document.getElementById("icons").innerHTML = '<canvas id="clear-day" width=100 height=100></canvas>';
   icons.set("clear-day", Skycons.CLEAR_DAY);
  }else if(weatherSummary.toLowerCase() == 'light intensity drizzle'){
    $(".body").css("background-image",'url("http://www.maclimatisation.net/wp-content/uploads/2017/01/children_running_in_the_rain-wallpaper-1366x768.jpg")');
  document.getElementById("icons").innerHTML = '<canvas id="sleet" width=100 height=100></canvas>';
    icons.set("sleet", Skycons.SLEET);
  }else if(weatherSummary.toLowerCase() == 'drizzle'){
    $(".body").css("background-image",'url("http://www.maclimatisation.net/wp-content/uploads/2017/01/children_running_in_the_rain-wallpaper-1366x768.jpg")');
  document.getElementById("icons").innerHTML = '<canvas id="sleet" width=100 height=100></canvas>';
  icons.set("Sleet", Skycons.SLEET);
  }else if(weatherSummary.toLowerCase() == 'broken clouds'){
    $(".body").css("background-image",'url("http://architectureimg.com/wp-content/uploads/2016/12/farms-horse-farm-winter-nevseoboi-ua-horses-clouds-fences-mountain-cool-wallpapers-1366x768.jpg")');
    document.getElementById("icons").innerHTML = '<canvas id="partly-cloudy-day" width=100 height=100></canvas>';
    icons.set("partly-cloudy-day", Skycons.PARTLY_CLOUDY_DAY);
  }
       $(".body").css("background-repeat","no-repeat");
      $(".body").css("background-size","cover");
       /*$(".body").css("background-position","center");*/
       icons.play();       
    });           
 };

//function to get location using google reverse geocoding api
function getLocation(latitude, longitude){
  //api key = AIzaSyAif_3QgUOsI8fEmWF1sVJZ5GCI7x1Q3IY  
  var link;
  link = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&key=" + "AIzaSyAif_3QgUOsI8fEmWF1sVJZ5GCI7x1Q3IY";
    
    $.getJSON(link,function(data){
     //alert(link);
     window.location1 = data.results[0].address_components[2].long_name;
     var html1 = "Location: " + data.results[0].address_components[1].long_name+","+
         data.results[0].address_components[2].long_name+","+data.results[0].address_components[3].long_name;    
    $("#location").text(html1);
  }); 
};

//event handler to change temrature to celcius or fahrenheit
$(".button").on("click",function(){
  
  //celcius = &#8451 \u2103
  //fahrenheit = &#8457 \u2109
  var newTemprature;
  var temprature
  var symbol = $(".button").html();
  
  if(symbol === '&#8451' || symbol === '\u2103'){
    temprature = $("#weather").html();
    temprature = Number(temprature.slice(-5));
    newTemprature = (temprature*9/5)+32;
    $("#weather").html("Temprature: "+newTemprature.toPrecision(4));
    $(".button").html("\u2109");
  }else if(symbol === '\u2109' || symbol === "&#8457"){
    temprature = $("#weather").html();   
    temprature = Number(temprature.slice(-5));
    newTemprature = (temprature-32)*5/9;
    $("#weather").html("Temprature: "+newTemprature.toPrecision(4));
    $(".button").html("\u2103");
    
  }
  
  });


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console