cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <body>
    <div class="container-fluid bg-1 text-center">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div id="time">13:30 AM</div>
                <h3 id="city-country" style="margin: 10px; font-family: 'Montserrat', sans-serif; font-size: 20px;">city, country</h3>

            </div>
        </div>

        <div class="row">
            <div class="col-md-4 col-md-offset-4">

                <div id="contents">

                    <div class="circle">
                        <!--img src="img/rain.jpeg" height="30" width="30"-->
                        <img id="image-weather" src="">

                        <p id="temperature" style="line-height: 90px; font-family: sans; padding: 0; margin: 0; font-size: 90px; font-family: monospace"></p>

                        <p id="weather-conditions" style="font-size: 15px"></p>
                    </div>

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <button id = "button-fahr" type="button" class="btn btn-default">&degF</button>
                <button id = "button-cels" type="button" class="btn btn-primary">&degC</button>
            </div>
        </div>

    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="js/scripts.js"></script>
</body>
            
          
!
            
              body {
    width: 100%;
    height: 100%;
    padding-top: 20px;
    /*background-image: url("https://source.unsplash.com/T7RlFC8dH60/1600x900");*/
    font-family: monospace;
    color: white;
}

#time {
    line-height: 0px;
    margin: 0;
    font-size: 15px;
}


/*
.bflock {
    border: 1px solid red;
    text-align: center;
    vertical-align: middle;
}*/

#content {
    padding-top: 40px;
}

#image {
    border-color: red;
}

.circle {
    display: flex;
    padding-top: 5px;
    background: grey;
    border-radius: 200px;
    color: white;
    height: 200px;
    width: 200px;
    display: table;
    margin: 20px auto;
    opacity: 0.8;
}

.circle p {
    vertical-align: middle;
    display: block;
}
/*
.tint {
    position: relative;
    height: 100%;
    float: left;
    margin-right: 20px;
    margin-bottom: 20px;
    cursor: pointer;
    box-shadow: rgba(0, 0, 0, .2) 3px 5px 5px;
}

.tint:before {
    height: 100%;
    content: "";
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 255, 255, 0.5);
    transition: all .3s linear;
}

.tint:hover:before {
    background: none;
}

.t2:before {
    background: rgba( 34, 45, 68, 0.5);
}
*/
.active {
    background: blue;
}

.inactive {
    background: #C8C8C8;
}

            
          
!
            
              /* The app is tested for Firefox, Safari and Chrome  */
/* The app run smoothly in codepen.io environment in Chrome */
/* There are location retrieval issues when run from codepen.io in Safari */

$(document).ready(function() {
    var lat = 0;
    var lng = 0;
    var temperature = 0;
    getLocationWeb();
    getTime();

    /* Retrieve user's location in Safari */
    function getAlternativeLocation() {
        /*
                $.getJSON("http://ip-api.com/json/?callback=?", function(data) {
                    updateCoordinates(data.lat, data.lon);
                    getWeather(data.lat, data.lon);
                });
        */
        var urlIpApi = "http://ip-api.com/json/?callback=?";
        $.ajax({
            dataType: "jsonp",
            url: urlIpApi,
            jsonCallback: 'jsonp',
            cache: false,
            success: function(data) {
                updateCoordinates(data.lat, data.lon);
                getWeather(data.lat, data.lon);
            }
        });
    }

    function updateCoordinates(latNew, lngNew) {
        lat = latNew;
        lng = lngNew;
    }

    /* This method of retrieving location is NOT working in Safari. However, works in Firefox and Chrome
    To retrievhe user's location in Safari we use an alternative method getAlternativeLocation()*/
    function getLocationWeb() {
        if (!navigator.geolocation) {
            console.log('Geolocation is not supported by your browser');
            return;
        }

        var geoOptions = {
            enableHighAccuracy: true
        };

        function geoError(error) {
            console.log("Can't retrieve the location using navigator.geolocation");
            getAlternativeLocation();
        }

        function geoSuccess(position) {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            updateCoordinates(lat, lng);
            getWeather(lat, lng);
        }
        navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOptions);
    }

    function getWeather(lat, lng) {
        var iconPath = "http://openweathermap.org/img/w/";
        var url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lng + "&units=metric&appid=393480cc10010dd643349a84fd338b7c";
        $.ajax({
            dataType: "jsonp",
            url: url,
            jsonCallback: 'jsonp',
            //data: { q: city },
            cache: false,
            success: function(data) {
                $("#image-weather").attr("src", iconPath + data.weather[0].icon + ".png");
                temperature = Math.round(data.main.temp);
                $("#temperature").text(Math.round(data.main.temp));
                $("#weather-conditions").text(data.weather[0].description);
                $("#time").text(getTime());
                setBodyImage(data.weather[0].main);
            }
        });

        getCityCountry(lat, lng);
    }

    /* We retrieve user's city and country based on the geographical coordinates because the service http://ip-api.com returns the location
    of the internet provider a user is on a mobile device with a roaming on provided by a different country */
    function getCityCountry(lat, lng) {
        var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&sensor=true";
        $.getJSON(url, function(response) {
            var addressComponentsArray = response.results[0].address_components;
            var clientLocation = {};
            for (var i = 0; i < addressComponentsArray.length; i++) {
                if (addressComponentsArray[i].types[0] === 'locality') {
                    clientLocation.city = addressComponentsArray[i].short_name;
                }
                if (addressComponentsArray[i].types[0] === 'country') {
                    clientLocation.country = addressComponentsArray[i].long_name;
                }
            }
            $("#city-country").html(clientLocation.city + ', ' + clientLocation.country);
        });
    }

    function setBodyImage(wCondition) {

        if (wCondition !== null) {

            var usplashBodyImageUrl = 'https://source.unsplash.com/1600x900/?' + wCondition.toLowerCase();
            $("body").css("background-image", "url(" + usplashBodyImageUrl + ")");
            $("body").addClass("tint t2");

        }

    }

    function getTime() {
        var currentdate = new Date();
        var datetime = currentdate.getHours() + ":" + currentdate.getMinutes();
        return currentdate.getHours() + ":" + currentdate.getMinutes();
    }


    /* Celsius/Fahrenheit buttons*/
    $('.btn').click(function() {
        $('.btn').removeClass('btn-primary').addClass('btn-default');
        $(this).removeClass('btn-default').addClass('btn-primary');
    });

    $('#button-cels').click(function() {
        $("#temperature").text(temperature);
    });

    $('#button-fahr').click(function() {
        $("#temperature").text(Math.round((temperature * (9 / 5)) + 32));
    });

});

            
          
!
999px
Loading ..................

Console