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.

            
              #app(ng-app='weatherApp')
 #main(ng-controller='MainCtrl' ng-cloak='')
   #loader(ng-hide='loaded')
     ul
       li
       li
       li
       li
       li
       li
     p Loading...
     #ensure: p If it doesn't load after a while, please ensure location services are turned on.
   #panel(ng-show='loaded')
     p 
       i.fa.fa-map-marker
       | {{location}}
     p 
       img#weather-icon
       | {{condition}}
     p 
       i.wi.wi-thermometer
       span.temp(ng-if='unit=="C"') {{temp}}
       span.temp(ng-if='unit=="F"') {{temp | fahrenheit | number:2}}
       | &nbsp
       a(href='#'): span.grow(ng-click='unit = unit == "C" ? "F" : "C"') {{unit}}
     p 
       span.updown
         i.fa.fa-arrow-down
         span.temp(ng-if='unit=="C"') {{temp_min}}
         span.temp(ng-if='unit=="F"') {{temp_min | fahrenheit | number:2}}
         | &nbsp
       span.updown
         i.fa.fa-arrow-up
         span.temp(ng-if='unit=="C"') {{temp_max}}
         span.temp(ng-if='unit=="F"') {{temp_max | fahrenheit | number:2}}
     
            
          
!
            
              @import url('https://cdnjs.cloudflare.com/ajax/libs/weather-icons/1.3.2/css/weather-icons.min.css');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css');
@import url(https://fonts.googleapis.com/css?family=Raleway);

body {
  background: no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover; 
}

p {
  font-size: 3.25rem;
  font-family: Raleway;
  font-weight: 500;
  color: white;
  text-shadow:
    1.5px 1.5px 0 #444,
    -0.5px -0.5px 0 #444,  
    0.5px -0.5px 0 #444,
    -0.5px 0.5px 0 #444,
    0.5px 0.5px 0 #444;
}

a {
  color: #00CCFF;
  text-decoration: underline;
}

.fa, .wi {
  margin: 0 1rem;
}

.updown {
  display: inline-block; 
}

#panel {
  text-align: center;
}

#panel p {
  text-transform: capitalize;
}

[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
}

::-webkit-scrollbar { 
    display: none; 
}

/* Make temperature unit grow on hover */
.grow {
  transition: all .3s ease-in;
  display: inline-block;
}
.grow:hover { transform: scale(1.3); }

/* Loading page animation */
#loader {
  position: fixed;
  margin: auto;
  left: 0;
  right: 0;
  top: 50%;
  width: 120px;
  
  ul {
    margin : 0;
    list-style:none;
    width:90px;
    position : relative;
    padding : 0;
    height:10px;
    
    li {
      position : absolute;
      width: 5px;
      height : 0;
      background-color: #444;
      bottom : 0;
    }
  }
}

#loader p {
  color: #444;
  text-shadow: none;
  font-size: 1rem;
  margin-left: 1rem;
}

#ensure {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
}
  

@keyframes sequence1 {
  0%{ height: 10px; }
  50%{ height:50px; }
  100%{ height: 10px; }
}

@keyframes sequence2 {
  0%{ height: 20px; }
  50%{ height: 65px; }
  100%{ height: 20px; }
}

#loader li:nth-child(1){
  left : 0;
  background-color: #E07253;
  animation: sequence1 1s ease infinite 0;
}
#loader li:nth-child(2){
  left : 15px;
  background-color: #F8C568;
  animation: sequence2 1s ease infinite 0.1s;
}
#loader li:nth-child(3){
  left : 30px;
  background-color: #8FC3A3;
  animation: sequence1 1s ease-in-out infinite 0.2s;
}
#loader li:nth-child(4){
  left : 45px;
  background-color: #6DC1D6;
  animation: sequence2 1s ease-in infinite 0.3s;
}
#loader li:nth-child(5){
  left : 60px;
  background-color: #8B6A8D;
  animation: sequence1 1s ease-in-out infinite 0.4s;
}
#loader li:nth-child(6){
  left : 75px;
  background-color: #404040;
  animation: sequence2 1s ease infinite 0.5s;
}
            
          
!
            
              var app = angular.module('weatherApp', []);

app.controller('MainCtrl', ['$scope', '$http', '$filter', function($scope, $http, $filter) {
  function getBackgroundURL(iconCode) {
    // http://openweathermap.org/weather-conditions for iconCode
    switch (iconCode.substr(0, 2)) {
      case '01': return 'https://wapcr.surge.sh/5CYT0nh.jpg';
      case '02': return 'https://wapcr.surge.sh/MYxa4nP.jpg';
      case '03': return 'https://wapcr.surge.sh/ryugoMP.jpg';
      case '04': return 'https://wapcr.surge.sh/bx6WnS0.jpg';
      case '09': return 'https://wapcr.surge.sh/W2pA4w7.jpg';
      case '10': return 'https://wapcr.surge.sh/e7ryyTy.jpg';
      case '11': return 'https://wapcr.surge.sh/nVJCOpp.jpg';
      case '13': return 'https://wapcr.surge.sh/KK7YuXQ.jpg';
      case '50': return 'https://wapcr.surge.sh/M8ELRXr.jpg';
      default: return 'http://prajwaldesai.com/wp-content/uploads/2014/01/error-code.jpeg';
    }
  }

  (function(e) {
    navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
    
    function geoError(error) {
      console.error(error);
      var h1 = document.createElement('h1');
      h1.textContent = 'Error: ' + error.message
      document.body.appendChild(h1);
    }
    
    function geoSuccess(position) {
      var latlon = {lat: position.coords.latitude, lon: position.coords.longitude};
      var weatherUrl = 'https://pro.openweathermap.org/data/2.5/weather?units=metric&callback=JSON_CALLBACK&APPID=1221ce13fef901a42f92c3255c556e0a';
      
      $http.jsonp(weatherUrl + '&lat=' + latlon.lat + '&lon=' + latlon.lon)
      .success(function(data) {
        var weatherIcon = document.querySelector('#weather-icon');
        var iconCode = data.weather[0].icon;
        weatherIcon.setAttribute('src', 'http://openweathermap.org/img/w/' + iconCode + '.png');
        console.log(getBackgroundURL(iconCode));
        document.body.style.backgroundImage = 'url(' + getBackgroundURL(iconCode) + ')';
        
        // Displays F by default to these countries
        // https://en.wikipedia.org/wiki/Fahrenheit#Usage
        var F = ['US', 'BS', 'BZ', 'KY', 'PW', 'AS', 'VI'];
        $scope.unit = ~F.indexOf(data.sys.country) ? 'F' : 'C';
        $scope.location = data.name;
        $scope.temp = data.main.temp;
        $scope.temp_min = data.main.temp_min;
        $scope.temp_max = data.main.temp_max;
        $scope.condition = data.weather[0].description;
        $scope.loaded = true;
        getAddress(latlon);
      })
      .error(function(e) {console.error(e)})
    };
    
    
    function getAddress(latlon) {
      // Use reverse geocoding API to get accurate user location, instead of OWM's location
      // JSONProxy because API doesn't support client-side requests
      var jsonProxyUrl = 'http://jsonp.afeld.me/?callback=JSON_CALLBACK&url=';
      var geocodeUrl = "https://maps.googleapis.com/maps/api/geocode/json?";
      geocodeUrl += '&latlng=' + latlon.lat + ',' + latlon.lon;
      geocodeUrl = encodeURIComponent(geocodeUrl);
      $http.jsonp(jsonProxyUrl + geocodeUrl)
      .success(function(data) {
        $scope.location = data.results[1].formatted_address;
      })
      .error(function(e) {console.error(e)})
    }
  })();
}]);

app.filter('fahrenheit', function() {
  return function(temp) {
    return temp * 9/5 + 32;
  };
});
            
          
!
999px
Loading ..................

Console