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.

            
              <div id="box" align="center">
  <header>
    <h1 class="dropshadow"><strong>It's No <a href="https://www.nytimes.com/2013/08/11/magazine/the-weather-god-of-oklahoma-city.html" target="_blank" style="color: cyan;">Gary England</a>,<br />But Here's The Weather</strong></h1>
  </header>

  <div id="city" class="dropshadow city">LOADING...</div> 
  <div id="temperature" class="dropshadow temp"></div>
  <div id="weatherDesc" class="dropshadow weather"></div>
  <div id="button"><button id="metric" class="btn btn-default btn-lg">Switch to Celcius</button><button id="imperial" class="btn btn-default btn-lg">Switch to Fahrenheit</button></div>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Oxygen:400,700);

input:focus,I 
select:focus,
textarea:focus,
button:focus {
    outline: none;
}

body {
  background: #84b0d7 url('http://www.mikemorkes.com/codepen/weather/sunny.jpg');
  background-position: 0 0;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
  text-align: center;
  color: #fff;
  font-family: 'Oxygen', sans-serif;
  padding-top: 20px;
}

#box {
  background-color: rgba(0, 0, 0, 0.5);
  padding: 20px 20px 35px;
  width: 90%;
  max-width: 600px;
  float: middle;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 15px;
}

.dropshadow {
  text-shadow: 0 0 4px #000000;
}

.city {
  font-size: 34px;
  margin-top: 50px;
}

.temp {
  font-size: 100px;
  font-weight: bold;
  margin-top: -20px;
}

.weather {
  font-size: 40px;
  margin-top: -25px;
}

#imperial {
  display: none;
  color: #333;
  margin-top: 20px;
}

#metric {
  color: #333;
  margin-top: 20px;  
}
            
          
!
            
              $(window).load(function() {

  var cTemp;
  var fTemp;

  //get the appropriate background image
  function backgroundImage(weather) {
    switch (weather.toLowerCase()) {
      //sunny
      case "sunny":
      case "mostly sunny":
      case "partly sunny":
      case "clear skies":
      case "clear":
        return "http://www.mikemorkes.com/codepen/weather/sunny.jpg";        
        
        
      //clouds
      case "mostly cloudy": 
      case "partly cloudy":
      case "scattered clouds":        
      case "overcast":
      case "hazy":
        return "http://www.mikemorkes.com/codepen/weather/cloudy.jpg";
        

      // rain
      case "rain":
      case "chance of rain":
        return "http://www.mikemorkes.com/codepen/weather/rainy.jpg";        

        
        //snow
      case "flurries":
      case "snow":
      case "chance of snow":
      case "sleet":
      case "chance of sleet":
        return "http://www.mikemorkes.com/codepen/weather/snowing.jpg";
        

        // extreme
      case "funnel cloud":
      case "squalls":
        return "http://www.mikemorkes.com/codepen/weather/extreme.jpg";
    }
  }

  $(document).ready(function() {
    getLocation();
  });

  // Run Geolocation to get user's lat and lon.
  function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var lat = position.coords.latitude;
        var lon = position.coords.longitude;
        getWeather(lat, lon);
      });
    }
  }
  //Get weather using lat and lon coordinates
  function getWeather(lat, lon) {

    //Call API
    $.ajax({
      type: 'GET',
      asynch: false,
      url: "https://api.wunderground.com/api/0826b7a9293c0565/conditions/q/" + lat + "," + lon + ".json",
      contentType: "application/json",
      dataType: "jsonp",
      //success function
      success: function(response) {
        //store user location
        var userLocation = response.current_observation.display_location.city;
        //store temperature in fahrenheit
        fTemp = Math.round(response.current_observation.temp_f);
        //store temperature in celcius
        cTemp = Math.round(response.current_observation.temp_c);
        //store weather description
        var weather = response.current_observation.weather;

        //Update inner html with response data
        city.innerHTML = userLocation;
        temperature.innerHTML = fTemp + "&#8457;";
        weatherDesc.innerHTML = weather;
        $("body").css("background-image", "url(" + backgroundImage(weather) + ")");
      }
    })
  }

  //button stuff

  $('#metric').click(function(evt) {

    evt.preventDefault();

    temperature.innerHTML = cTemp + "&#8451;";

    document.getElementById("metric").style.display = "none";
    document.getElementById("imperial").style.display = "block";

  }); // end button function

  $('#imperial').click(function(evt) {

    evt.preventDefault();

    temperature.innerHTML = fTemp + "&#8457;";

    document.getElementById("metric").style.display = "block";
    document.getElementById("imperial").style.display = "none";

  }); // end button function  

});
            
          
!
999px
Loading ..................

Console