css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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="row" id="buttons-container">
    <button class="btn" id="fahrenhiet-button">F°</button>
    <button class="btn btn-primary" id="celsuis-button">C°</button>
    
</div>
    
<div class="container text-center">
    <span style="font-size : 30px" id="date"></span><br>
    <span style="font-size : 50px" id="location"></span><br>
    <span style="font-size : 150px" id="temp"></span><br>
    <img id="weatherIcon"><br>
    <span style="font-size : 30px" id="weatherCondition"></span><br>
    <span style="font-size : 25px" id="windSpeed"></span>

</div>
    
<div class="panel-footer Transparency">
        <span><i>Powred by <a href='https://openweathermap.org/' target='_blank'><img src="https://www.esolve.co.za/images/assets/logo_OpenWeatherMap_orange_website.png" width="240" height="30" id="openWeatherMapLogo"></a>,  Created by 
    <a href='https://github.com/sendja-3360' target='_blank'>SENDJASNI</a></i></span>
</div>    
            
          
!
            
              body {
    margin-top: 5%;
    font-family:  Arial, sans-serif;
}

#buttons-container {
    position: fixed;
    padding-left: 10%;
    top : 0%;
}

.center {
    position: relative;
    margin-top: 10%;
    width: 60%;
    margin-left: 20%;
}

.Transparency {
    background-color: rgba(90, 125, 0, 0.5);

}

span {
  color : #200000;
}
.panel-footer {
    position: absolute;
    width: 100%;
    bottom: 0%;
    left: 0%;
    text-align: center;
}
            
          
!
            
              /*

 Code by SENDJASNI

*/

$(document).ready(function () {
    var data;

    //get the lat and long 
      function initGeolocation(){
        if( navigator.geolocation ){
           // Call getCurrentPosition with success and failure callbacks
           navigator.geolocation.getCurrentPosition( success, fail );
        }else {
           alert("Sorry, your browser does not support geolocation services.");
        }
     
    }function success(position){

        var longitude = position.coords.longitude;
        var latitude = position.coords.latitude
        
         getCityId(latitude, longitude);
     
    }function fail(){
        // Could not obtain location
         alert("Sorry, something went wrong Could not obtain location.");
     }
    
    
    //get the data from the openWeatherMap API
    function getCityId(lat, lon) {
        var link = 'http://api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + '&APPID=f6d4f74a914927bf429602afcac80854';

        $.getJSON(link, function (json) {
            $.getJSON('http://api.openweathermap.org/data/2.5/weather?id='+json.id+'&APPID=f6d4f74a914927bf429602afcac80854', function(weather){
               displayData(weather); 
            });
            data = json;
        });

    }
    
    
    //Display the data in the web page
    function displayData(data) {
        // getting the current date
        var date = new Date();
        var strDate = (GetMonthName(date.getMonth()+1)) +' '+ date.getDate() +', '+date.getFullYear();
             
        var temp =  kelvinToCelsuis(data.main.temp) + " C°";
        var windSpeed = 'Wind Speed : ' + data.wind.speed + ' Mph';
        var strWeatherCon = data.weather[0].description;
        var weatherCondition = strWeatherCon[0].toUpperCase() + strWeatherCon.slice(1);
        var location = data.name +', '+ data.sys.country;

        $('#weatherIcon').attr('src', 'http://openweathermap.org/img/w/'+data.weather[0].icon+'.png');
        $('#temp').append(temp);
        $('#date').append(strDate);
        $('#location').append(location);
        $('#windSpeed').append(windSpeed);
        $('#weatherCondition').append(weatherCondition);

        //changing the background
        changeBackground(data.weather[0].description);

    }


    //convert temp from kelvin to celsuis
    function kelvinToCelsuis(temp) {
        return Math.round(temp - 273.15);
    }

    //convert temp from kelvin to fahrenhiet
    function kelvinToFahrenhiet(temp) {
        var fahrenTemp = ((temp * 9) / 5) - 459.67
        return Math.round(fahrenTemp);
    }
    
    //activating the button to display the temp with the desire metric  
    $('div button').on('click', function () {
        $(this).addClass('btn-primary');
        $(this).siblings().removeClass('btn-primary');
        
    });
    
    //changing the display metric to fahrenhiet
    $('#fahrenhiet-button').on('click', function(){
            $('#temp').html(kelvinToFahrenhiet(data.main.temp) + "  F°");
    });
    
    //changing the display metric to celsuis
    $('#celsuis-button').on('click', function(){
            $('#temp').html(kelvinToCelsuis(data.main.temp) + "  C°");
    });
    
    //converting numbers to month name
    function GetMonthName(monthNumber) {
        var months = ['January', 'February', 'March', 'April', 'May', 'June',
                     'July', 'August', 'September', 'October', 'November', 'December'];
        return months[monthNumber - 1];
    }
    
    function changeBackground(discription){
        var link;
        backgrounds.forEach(function(val){
          if(val.id == discription)
              link = val.link;
            });
        $('body').css("background-image", "url("+link+") 100% 100%");  
    }

    //sarting the sevice
initGeolocation();


});

var backgrounds = [  
   {  
      "id":"clear sky",
      "link":"http://wallpaperstock.net/clear-sky-field--hay-bale-wallpapers_41557_1920x1080.jpg"
   },
   {  
      "id":"few clouds",
      "ink":"https://acadiansoul.files.wordpress.com/2012/08/eagle-lake-and-bubble-pond-july-12-032.jpg"
   },
   {  
      "id":"scattered clouds",
      "link":"https://pbs.twimg.com/media/CtYsmZPXYAIE1nx.jpg"
   },
   {  
      "id":"broken clouds",
      "link":"http://www.blogforphotos.com/images/hdr-in-helsinki/helsinki-lapinlahden-silta-hdr.jpg"
   },
   {
     "id":"few clouds",
     "link":"https://i.ytimg.com/vi/84YnC4meEl4/maxresdefault.jpg"
   },
   {  "id":"overcast clouds",
      "link":"https://theholywild.files.wordpress.com/2013/04/dsc02270.jpg"
    
   },
   {
     "id":"light rain",
     "link":"https://i.ytimg.com/vi/MR47cSm4OWk/maxresdefault.jpg"
   },
   {  
      "id":"shower rain",
      "link":"http://previews.123rf.com/images/tuk69tuk/tuk69tuk1506/tuk69tuk150600030/40640521-Drops-of-rain-on-glass-with-filter-effect-retro-vintage-style-Stock-Photo.jpg"
   },
   {  
      "id":"rain",
      "link":"https://az616578.vo.msecnd.net/files/2016/05/28/636000076698153744-318535480_maxresdefault.jpg"
   },
   {  
      "id":"thunderstorm",
      "link":"https://i.ytimg.com/vi/6sBqh_IA58Q/maxresdefault.jpg"
   },
   {  
      "id":"snow",
      "link":"http://kingofwallpapers.com/snow/snow-010.jpg"
   },
   {  
      "id":"mist",
      "link":"https://danaelysephotography.files.wordpress.com/2013/01/1dsc_8901.jpg"
   }
]



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

Console