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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>

</script>

<style>
  body{
  background-position: center; 
  background-repeat: no-repeat;
  background-size: 100% 900px;
  font-size: 20px;
  }
</style>
<body>
<center>
  </br></br>
<p><button class="btn btn-success animated rubberBand" onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>

<p id="demo"></p>
<div id='loc' class="label label-primary">Location</div>
<div id='tem' class="label label-default">temperature</div>
<div id='feels' class="label label-info">feels like</div>
  <div id='icon'><img src=""></img></div>
</center>
</body>
            
          
!
            
              function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';

    var img = new Image();
    img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
    $(document).ready(function($) {
  var tempchg1 = "temp_f";
  var tempchg2 = "temp_c";
  var tempchg = "f";
  navigator.geolocation.getCurrentPosition(success, error);
  $.ajax({
  url : "http://api.wunderground.com/api/dcea7c539cb987ca/geolookup/conditions/q/" + latitude + "," + longitude + ".json",
  dataType : "jsonp",
  success : function(parsed_json) {
  var location = parsed_json['location']['city'];
  var temp_f = parsed_json['current_observation'][tempchg1] + tempchg;
  var temp_c = parsed_json['current_observation'][tempchg2] + " C";
  var feels = parsed_json['current_observation']['weather'];
  var icon = parsed_json['current_observation']['icon_url'];
  // alert("Current temperature in " + location + " is: " + temp_f + feels); 
  $('#loc').html(location);
  $('#tem').html(temp_f);
  $('#feels').html(feels);
  $('#icon img').attr('src', icon);
  if (feels==="Overcast"){
    $('body').css({background: 'url(https://ununsplash.imgix.net/uploads/141362941583982a7e0fc/abcfbca1?fit=crop&fm=jpg&h=800&q=75&w=1550) no-repeat fixed top center'});
    }
  else if (feels==="rain"){
  tempchg1 = "temp_c";
   tempchg = "c";
    $('body').css({background: 'url(https://ununsplash.imgix.net/18/trickle.JPG?fit=crop&fm=jpg&h=800&q=75&w=1050) no-repeat fixed top center'});
    }
   else{
  tempchg1 = "temp_f";
  tempchg = "f";
    $('body').css({background: 'url(https://ununsplash.imgix.net/18/trickle.JPG?fit=crop&fm=jpg&h=800&q=75&w=1550) no-repeat fixed top center'});
    }
  }
  });
   $('#tem').click(function(){       
      alert("feels: " + temp_c);
    });
});
    output.appendChild(img);
  };

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  };

  output.innerHTML = "<p>Locating…</p>";

  navigator.geolocation.getCurrentPosition(success, error);
}

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

Console