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.

            
              <section class="weather">
  <p class="intro">
    Looking out the window...
  </p>
  <p class="info">
  </p>
</section>

<iframe id="sound" width="0" height="0" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?visual=false&url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F249566993&show_artwork=false&auto_play=false&secret_token=s-FB08V"></iframe>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lato:100,900);
@import url(https://fonts.googleapis.com/css?family=Abril+Fatface);

html {
  box-sizing: border-box;
  font-size: 62.5%;
  height: 100%;
}
*, *:before, *:after {
  box-sizing: inherit;
}

/*
  : VARS
*/

// basic
$bg-default:#11D3BC;
$color-default: #fff;

// theme - sunny
$bg-sunny: #8DC6FF;
$color-sunny: #fff;

// theme - cloudy
$bg-cloudy: #D3D4D8;
$color-cloudy: #4D606E;

// theme - rainy
$bg-rainy: #47555E;
$color-rainy: #EEEEEE;

$bg-stormy: #435055;
$color-stormy: #E6E6E6;

$bg-snowy: #F8F8F8;
$color-snowy: #E6E6E6;


$easing: cubic-bezier(.64,.57,.47,1.29);
//cubic-bezier(.65, 1.95, .03, .32);//cubic-bezier(.64,.57,.47,1.29);

$breakpoint: 1024px;
$breakpoint-small: 600px;


body {
  background: $bg-default;
  color: $color-default;
  min-height: 100%;
  transition: all 0.6s ease;

  
  &.theme-sunny {
    background: $bg-sunny;
    color: $color-sunny;
  }
  &.theme-cloudy {
    background: $bg-cloudy;
    color: $color-cloudy;
  }
  &.theme-rainy {
    background: $bg-rainy;
    color: $color-rainy;
  }
  &.theme-stormy {
    background: $bg-stormy;
    color: $color-stormy;
  }
  &.theme-snowy {
    background: $bg-snowy;
    color: $color-snowy;
  }
  &.theme-default {
    background: $bg-default;
    color: $color-default;
  } 
}
.weather {
    
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate3d(-50%,-50%,0);
  font-size: 80px;
  
  @media only screen and (max-width: $breakpoint-small) {
    font-size: 40px;
  }
  
  font-family: 'Lato';
  width: 80%;
  text-align: center;
  
  .intro {
    opacity : 1;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate3d(-50%,-50%,0);
    &.hide {
      transition: all 2s ease;
      opacity : 0;
    }
  }
  
  .info {
    opacity : 0;
    &.show {
      transition: all 2s ease;
      opacity : 1;
    }
    font-weight: 100;
    perspective: 1500px;
    
    .city {
      display: inline-block;
      padding: 0 10px 0 0;
      @media only screen and (max-width: $breakpoint) {
        padding: 0;
        .theme-sunny & {
          border-bottom: 1px solid $color-sunny;
        }
        .theme-cloudy & {
          border-bottom: 1px solid $color-cloudy;
        }
        .theme-stormy & {
          border-bottom: 1px solid $color-stormy;
        }
        .theme-snowy & {
          border-bottom: 1px solid $color-snowy;
        }
        .theme-rainy & {
           border-bottom: 1px solid $color-rainy;
        }
        .theme-default & {
          border-bottom: 1px solid $color-default;
        }
      }
    }
    .divisor {
      display: inline-block;
      padding-right: 10px;
      @media only screen and (max-width: $breakpoint) {
        display: none;
      }
    }
    .forecast {
      position: relative;
      display:inline-block;
      font-weight: 900;
      text-transform: uppercase;
      transform-origin: 50% 0%;
      transform-style: preserve-3d;
      transition: transform 0.6s $easing;
      background: $bg-default;
      
      @media only screen and (max-width: $breakpoint) {
        display: block;
      }
      
      .theme-sunny & {
        background: $bg-sunny;
      }
      .theme-cloudy & {
        background: $bg-cloudy;
      }
      .theme-stormy & {
        background: $bg-stormy;
      }
      .theme-snowy & {
        background: $bg-snowy;
      }
      .theme-rainy & {
        background: $bg-rainy;
      }
      .theme-default & {
        background: $bg-default;
      }
      &.rotate {
        transform: rotateX(90deg);
        transition: transform 0.6s ease;
      }
      // temperature
      &:before {
        position: absolute;
        text-align: left;
        top: 100%;
        left: 0;
        width: 100%;
        height: 100%;
        content: attr(data-temp);
        transition: background 0.6s;
        transform: rotateX(-90deg);
        transform-origin: 50% 0;
        display: block;
        background: $bg-default;
        
        @media only screen and (max-width: $breakpoint) {
          text-align: center;
        }
        
        .theme-cloudy & {
          background: $bg-cloudy;
        }
        .theme-snowy & {
          background: $bg-snowy;
        }
        .theme-sunny & {
          background: $bg-sunny;
        }
        .theme-stormy & {
          background: $bg-stormy;
        }
        .theme-rainy & {
          background: $bg-rainy;
        }
        .theme-default & {
          background: $bg-default;
        }
      }
    }
  }
  
  &.show {
    transition: all 2s ease;
    opacity : 1;
  }
}

// hide soundcloud player
iframe {
  width: 0;
  height:0;
}


            
          
!
            
              var app = {};
app = {
  myCity: 'Milano',
  myState: 'Italy',
  yahooUrl: '',
  codes: {
    stormy: [0, 1, 2, 3, 4, 37, 38, 39, 45, 47],
    snowy: [5, 6, 7, 13, 14, 15, 16, 17, 18, 41, 42, 43, 46],
    rainy: [8, 9, 10, 11, 12, 35, 40],
    cloudy: [26, 27, 28, 29, 30, 44],
    sunny: [31, 32, 33, 34, 36],
    default: [19, 20, 21, 22, 23, 24, 25],
    error: [3200]
  },
  audio: $('#audio'),
  audioTracks: {
    stormy: 'https%3A//api.soundcloud.com/tracks/249732836',
    snowy: 'https%3A//api.soundcloud.com/tracks/249793355',
    rainy: 'https%3A//api.soundcloud.com/tracks/249566993',
    cloudy: 'https%3A//api.soundcloud.com/tracks/249665740',
    sunny: 'https%3A//api.soundcloud.com/tracks/249665740', 
    default: 'https%3A//api.soundcloud.com/tracks/249665740',
    error: ''
  },
  forecastTxt: null,
  convert: function(fahrenheit) {
    C = (fahrenheit - 32) * 5 / 9;
    return Math.round(C);
  },
  rotator: function() {
    app.forecastTxt.toggleClass('rotate');
  },
  streamAudio: function(track) {
    /* SOUNDCLOUD API */
    /* IFRAME must have src specified otherwise SC.Widget returns empty obj */
    SC.initialize({
      client_id: '9003d9a0ea57e7f021bb8447bba307ed'
    });

    var track_url = app.audioTracks[track];

    var iframeElement = document.getElementById('sound');
    var widget = SC.Widget(iframeElement);

    widget.load(track_url, {
      show_artwork: false
    });

    /* Loop audio track */
    widget.bind(SC.Widget.Events.READY, function() {
      widget.play();
      widget.bind(SC.Widget.Events.FINISH, function() {
        widget.seekTo(0);
        widget.play();
      });
    });
  },
  geoError: function(){
    app.getWeather();
  },
  geoSuccess: function(position) {
    
    var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    app.geocoder.geocode({
      'latLng': latlng
    }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
          //find country name
          for (var i = 0; i < results[0].address_components.length; i++) {
            for (var b = 0; b < results[0].address_components[i].types.length; b++) {
              if (results[0].address_components[i].types[b] == "country") {
                country = results[0].address_components[i];
              }
              
              // there are different types that might hold a city "administrative_area_level_1" usually does
              // in come cases looking for sublocality type will be more appropriate
              if (results[0].address_components[i].types[b] == "locality" ) {
                city = results[0].address_components[i];
                break;
              }
            }
          }
          //city and state data
          app.myCity = city.short_name;
          app.myCountry = country.long_name;
          

        } else {
          //alert("No results found");
          app.myCity = 'Milano';
        }
        
        app.getWeather();
        
      } else {
        //alert("Geocoder failed due to: " + status);
        app.getWeather();
      }
    });

    
  },
  geocoder : null,
  getWeather: function() {
    
    app.yahooUrl = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22' + app.myCity + '%2C%20' + app.myState + '%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
    
    $.ajax({
        method: "GET",
        url: app.yahooUrl,
        dataType: 'json'
      })
      .done(function(data) {
        //var fcObj = data.query.results.channel.item.forecast[0];
        //app.forecastTxt.html(fcObj.text);
        //app.forecastTxt.attr('data-temp', app.convert(fcObj.low) + '°- '    +app.convert(fcObj.high) + '°' );
        var fcObj = data.query.results.channel.item.condition;

        for (var k in app.codes) {
          // use hasOwnProperty to filter out keys from the Object.prototype
          if (app.codes.hasOwnProperty(k)) {
            //console.log('key is: ' + k + ', value is: ' + app.codes[k]);
            if ($.inArray(parseInt(fcObj.code), app.codes[k]) > -1) {
              $('body').attr('class', 'theme-' + k);
              app.streamAudio(k);
              break;
            }
          }
        }

        $('.weather .info').html('<span class="city">'+app.myCity+'</span><span class="divisor">/</span><span class="forecast" data-temp=""></span>');
        
        app.forecastTxt = $('.forecast');
        app.forecastTxt.html(fcObj.text);
        app.forecastTxt.attr('data-temp', app.convert(fcObj.temp) + '°');

        $('.weather .intro').addClass('hide');
        
        $('.weather .info').addClass('show');
        window.setInterval(app.rotator, 5000);
      });
  },
  init: function() {
    if (navigator.geolocation) {
      app.geocoder = new google.maps.Geocoder();
      navigator.geolocation.getCurrentPosition(app.geoSuccess, app.geoError);
    } else {
      //error('not supported');
      app.getWeather();
    }
  }
}

// init on DOM ready
$(function() {
  app.init();
});
            
          
!
999px
Loading ..................

Console