123

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.

            
              <div class="weather-app-wrapper">
  <div class="current-weather">

    <div class="app-location">
      <img src="http://www.iconsdb.com/icons/preview/white/map-marker-xxl.png" />
      <p class="current-country"></p>
      <p class="current-time"></p>
    </div>
    <div class="app-name">
       <!--<h1>Temp&eacute;rature locale</h1>-->
                  <div>
        <canvas id="icon1" width="128" height="128"></canvas>
      </div>
      <span class="summary"></span>
      <button class="celcius degree">&deg;C</button>
      <button class="fahreneit degree">&deg;F</button>
      <div class="temperature"></div>
      </div>
  </div>
</div>
<div class="copyright"><p>Developed by <a href="#">Koffi Eli KPONBLANOU</a></p></div>
            
          
!
            
              body{
  padding: 0;
  margin: 0;
  background-color: #1d1f20;
  font-family: 'Roboto', sans-serif;
}

.weather-app-wrapper{
  width:  720px;
  height: auto;
  margin: auto;
  max-width: 100%;
  background-color: #343436;
  margin-top: 5%;
  border-radius: 8px;
  box-shadow: 2px 2px 8px 2px;
  overflow: hidden;
}

.current-weather{
  height: 100%;
  padding: 16px;
  background: linear-gradient(-30deg,#ffda49, #ff0303);
}

.app-name{
  margin: 0;
  padding: 16px;
  color: #fff;
  font-size: 32px;
  display: inline-block;
  vertical-align: top;
  text-align: right;
  width: calc(60% - 64px);
}

.app-name h1{
  margin-top: 0;
}

.temperature {
  font-size: 4.0em;
}
.app-location{
  padding: 16px;
  display: inline-block;
  vertical-align: top;
  color: #fff;
  width: calc(40% - 32px);
}

.app-location img{
  width: 56px;
  height: 56px;
  display: block;
}

.local-temperature-box{
  width: 100%;
  height: 100px;
  color: #fff;
}

.degree{
  border: none;
  color: #fff;
  background-color: rgba(0,0,0,.1);
  padding: 8px 16px;
  font-weight: 400;
  font-size: 16px;
  border-radius: 50em;
  cursor: pointer;
}

.copyright{
  text-align: center;
  color: #fff;
}

.copyright a{
  color: #c5c3c6;
}
            
          
!
            
              jQuery(function($){
  var proxy = "https://cors-anywhere.herokuapp.com/";
  var weatherBoxHTML = "<h1>LOCAL WEATHER APP</h1>";
  var darkSkyKey = "3b17cbc9cda151734353bb257501f4d4";
  var forecastUrl = "https://api.darksky.net/forecast/";
  var dataExcluded = "exclude=[minutely,hourly,daily]";
  var lang = "lang=fr";
  var units = "units=auto";
  var myLongitude = "";
  var myLatitude = "";
  
  if( navigator.geolocation ){
    console.log("GEOLOCATION AVAILABLE\n");
     navigator.geolocation.getCurrentPosition(getPositionCoords);
    
     } else {
       console.log("GEOLOCATION NOT AVAILABLE\n");
     }
  function getPositionCoords(position){
    myLongitude = position.coords.longitude;
    myLatitude = position.coords.latitude;
    
   console.log("\n Ma latitude: "+myLatitude+", et ma Longitude: "+myLongitude+"\n");
    
    forecastUrl += darkSkyKey + "/"+myLatitude+","+myLongitude+"?"+dataExcluded+"&"+lang+"&"+units;
    console.log("\n"+forecastUrl);
    
    $.getJSON(proxy+forecastUrl).done(function(data){
      console.log("Load Dark Sky API SUCCEEDED\n");
      console.log(""+JSON.stringify(data));
      $(".current-country").text(data["timezone"]);
      
      var myDate = new Date(data["currently"]["time"]*1000);
      var hours = myDate.getHours();
      var minutes = myDate.getMinutes();
      if(minutes < 9){
         minutes = "0"+minutes;
         }
      $(".current-time").text(hours+":"+minutes);
      var current_temperature =Math.round(data["currently"]["apparentTemperature"]);
 $(".summary").html(data["currently"]["summary"]);     $(".temperature").html(current_temperature+"&deg;C");
      
var temp_in_fahreneit = Math.round(data["currently"]["apparentTemperature"]*1.8+32);
 $(".fahreneit").on("click", function(e){
        e.preventDefault();
$(".temperature").html(temp_in_fahreneit+"&deg;F");
      });
      
      $(".celcius").on("click",function(e){
        e.preventDefault();
        $(".temperature").html(current_temperature+"&deg;C");
      });
      var skycons = new Skycons({"color": "white"});
      var dataIcon = data["currently"]["icon"];
      //skycons.add("icon1", Skycons.dataIcon);
      skycons.set("icon1", dataIcon);
      skycons.play();
      // Change background depends on weather
      // $(".icon").html(data["currently"]["icon"]);
      var climate_nature = data["currently"]["icon"];
                console.log(climate_nature);
      switch(climate_nature){
        case climate_nature = "partly-cloudy-night":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg,#131862,#87889c)"
          );
          break;
          
        case climate_nature = "rain":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg,#b4e7dc,#464e74)"
          );
          break;
          
        case climate_nature = "partly-cloudy-day":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #1c5e89, #7eaa5d)"
          );
          break;
          
        case climate_nature = "clear-day":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #58adfb, #a2d4f8)"
          );
          break;
          
        case climate_nature = "clear-night":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #08182d, #10426a)"
          );
          break;
          
        case climate_nature = "sleet":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #a91428, #92918f)"
          );
          break;
          
        case climate_nature = "wind":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #ff8500, #66a182)"
          );
          break;
          
        case climate_nature = "fog":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #c6878f, #b79d94)"
          );
          break;
        case climate_nature = "cloudy":
          $(".current-weather").css(
            "background", "linear-gradient(-30deg, #46494c, #c5c3c6)"
          );
          break;
    }
      /*  $(".current-weather").css(
    "visibility","visible"
  );*/
      
    }).fail(function(){
      console.log("Load dark sky API FAILED\n");
    });
  }
 
  
  function afficherUI(str){
    weatherBoxHTML += str;
    $("#weatherBox").html(weatherBoxHTML);
  }
});
            
          
!
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