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.

            
              <div id="weather-video"></div>
<div class="container narrow">
  <div id="weather-info">
    <div class="row">
      <div class="col-md-12" id="device-info">
        <h1>This app needs access to your location to work.</h1>
        <p>If you didn't get a prompt to allow access to this info then you can either view on a desktop/laptop or search for a solution for your device/browser on Google.</p>
      </div>
      <div class="col-md-6">
        <canvas class="center-block" id="weather-icon" width="150" height="150"></canvas>
      </div>
      <div class="col-md-6 text-center" id="temperature"></div>
    </div>
    <div class="row">
      <p class="col-md-12 text-center" id="weather-report"></div>
    <div class="row">
      <div class="col-md-6 text-center" id="location"></div>
      <div class="col-md-6 text-center" id="date-time"></div>
    </div>
  </div>
  <div class="row">
    <div id="video-controls" class="col-md-6"></div>
    <div id="info-controls" class="col-md-6"></div>
  </div>
</div>

<div class="container" id="video-details">
  <div class="row">
    <div id="video-title" class="col-md-12 text-center"></div>
  </div>
</div>
            
          
!
            
              html {
  height: 100%;
}

body {
  font-size: 20px;
  font-weight: bold;
  color: #114b5f;
  background: #000;
  height: 100%;
}

.btn-lg {
  font-size: .75em;
  font-weight: bold;
}

button {
  color: #e4fde1;
  background: #456990;
}

.greyed-out {
  color: grey;
}

h1 {
  text-shadow: 2px 2px 1px rgba(150, 150, 150, 1);
}

.narrow {
  padding-top: 20px;
}

#showHideWeather, #playPauseButton {
  margin-top: 10px;
}

#temperature {
  height: 150px;
  line-height: 150px;
}

#temperature, #weather-report {
  font-size: 2em;
  /* https://css-tricks.com/almanac/properties/t/text-shadow/ */
  text-shadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0, 0, 0, .1), 0 0 5px rgba(0, 0, 0, .1), 0 1px 3px rgba(0, 0, 0, .3), 0 3px 5px rgba(0, 0, 0, .2), 0 5px 10px rgba(0, 0, 0, .25), 0 10px 10px rgba(0, 0, 0, .2), 0 20px 20px rgba(0, 0, 0, .15);
}

#video-details {
  position: fixed;
  bottom: 0;
  width: 100%;
}

#weather-video {
  position: fixed;
  z-index: -99;
  width: 100%;
  height: 100%;
}

@media only screen and (max-width: 1200px) {
  body {
    font-size: 24px;
  }
}

@media only screen and (max-width: 992px) {
  body {
    font-size: 22px;
  }
}

@media (min-width: 768px) {
  .narrow {
    max-width: 730px;
  }
}

@media only screen and (max-width: 768px) {
  body {
    font-size: 18px;
  }
}
            
          
!
            
              if ("geolocation" in navigator) {
  var latitude = 0;
  var longitude = 0;
  var apiKeyForecast = "bba28e3b75f1f0bd9371d7e584831ef9";
  var apiKeyGoogle = "AIzaSyCATJTheVt2HXEYZujZanpHikRZHciUa5E";
  var forecastURL = "";
  var googleURL = "";
  var videoObject = {
    "clear-day": ["Finley Quaye - Sunday Shining", "1-ORJddr0QY"],
    "clear-night": ["The Rolling Stones - Moonlight Mile", "0Gy3PH4Sf6g"],
    "rain": ["Missy Elliott - The Rain", "hHcyJPTTn9w"],
    "snow": ["Red Hot Chili Peppers - Snow", "fmXLzY8kbYA"],
    "sleet": ["Billie Holiday - Stormy Weather", "EIgVCU19pjg"],
    "wind": ["Scorpions - Wind Of Change", "n4RjJKxsamQ"],
    "fog": ["Radiohead - Fog", "wWucA7e-LRg"],
    "cloudy": ["Kate Bush - Cloudbusting", "pllRW9wETzw"],
    "partly-cloudy-day": ["The Orb - Little Fluffy Clouds", "aTxg-15TfHg"],
    "partly-cloudy-night": ["Black Roots - Cloudy Night", "FDfVv5es0VQ"]
  };
  var videoTitle;
  var videoID;
  var player;
  var temperature;
  var isPlaying;
  var isFahrenheit = true;
  var showWeather = true;

  function positionFound(pos) {
    latitude = pos.coords.latitude;
    longitude = pos.coords.longitude;
    forecastURL = "https://api.forecast.io/forecast/" + apiKeyForecast + "/" + latitude + "," + longitude;
    googleURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&key=" + apiKeyGoogle + "&language=en-GB&result_type=locality";
    getLocation(googleURL);
    getWeather(forecastURL);
  };

  navigator.geolocation.getCurrentPosition(positionFound);

  function getWeather(forecastURL) {
    var weatherIcon;
    var skycons;
    $.ajax({
      url: forecastURL,
      dataType: "jsonP",
      success: function(weatherData) {
        $('#device-info').hide();
        
        weatherIcon = weatherData.currently.icon;

        setBackground(weatherIcon);

        skycons = new Skycons({
          "color": "#f45b69"
        });
        skycons.add(document.getElementById("weather-icon"), weatherIcon);
        skycons.play();

        $("#weather-report").html(weatherData.currently.summary);
        temperature = Math.round(weatherData.currently.apparentTemperature);
        $("#temperature").html('<span id="temp-value"></span>&deg;<button id="tempUnits" class="btn btn-lg" title="Click to change units"><span id="fahrenheit" class="">F</span>/<span id="celsius" class="greyed-out">C</span></button>')
        $("#temp-value").html(temperature);
        displayDate(weatherData.currently.time);
        $('#video-controls').html('<button id="playPauseButton" class="btn btn-lg center-block">Pause</button>');
        $('#info-controls').html('<button id="showHideWeather" class="btn btn-lg center-block">Hide Info</button>');
      }
    });
  }

  function getLocation(googleURL) {
    $.getJSON(googleURL, function(data) {
      $("#location").html(data.results[0].formatted_address);
    });
  }

  function displayDate(now) {
    var date = new Date(now * 1000);
    var monthsArray = ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
    var suffixArray = ["st", "nd", "rd", "th"];
    var year = date.getFullYear();
    var month = date.getMonth();
    var day = date.getDate();
    var hours = "0" + date.getHours();
    var minutes = "0" + date.getMinutes();
    var nowString = day + "<sup>" + (day > 3 ? suffixArray[3] : suffixArray[day - 1]) + "</sup> " + monthsArray[month] + ", " + year + " - " + hours.slice(-2) + ":" + minutes.slice(-2);
    $("#date-time").html(nowString);
  }

  function setBackground(weatherType) {
    videoTitle = videoObject[weatherType][0];
    videoID = videoObject[weatherType][1];
    var tag = document.createElement('script');
    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    $("#video-title").html(videoTitle);
  }

  function onYouTubeIframeAPIReady() {
    player = new YT.Player('weather-video', {
      videoId: videoID,
      playerVars: {
        'iv_load_policy': 3,
        'loop': 1,
        'modestbranding': 1,
        'rel': 0,
        'showinfo': 0,
        'controls': 0
      },
      events: {
        'onReady': onPlayerReady
      }
    });
  }

  function onPlayerReady(event) {
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
      isPlaying = false;
      $("#playPauseButton").html("Play");
    } else {
      event.target.playVideo();
      isPlaying = true;
    }
  }

  $('body').on('click', '#playPauseButton', function () {
    if (isPlaying) {
      player.pauseVideo();
      isPlaying = false;
      $('#playPauseButton').html('Play');
    } else {
      player.playVideo();
      isPlaying = true;
      $('#playPauseButton').html('Pause');
    }
  });
  
  $('body').on('click', '#tempUnits', function() {
    if (isFahrenheit) {
      fahrenheitToCelsius();
      $("#fahrenheit").attr("class", "greyed-out");
      $("#celsius").removeClass("greyed-out");
      isFahrenheit = false;
    } else {
      $("#temp-value").html(temperature);
      $("#celsius").attr("class", "greyed-out");
      $("#fahrenheit").removeClass("greyed-out");
      isFahrenheit = true;
    }
  });
  
  function fahrenheitToCelsius() {
    var celsiusTemp = Math.round((temperature - 32) / 1.8);
    $("#temp-value").html(celsiusTemp);
  }
  
  $('body').on('click', '#showHideWeather', function() {
    if (showWeather) {
      $("#weather-info").slideUp();
      showWeather = false;
      $("#showHideWeather").html("Show Info");
    } else {
      $("#weather-info").slideDown();
      showWeather = true;
      $("#showHideWeather").html("Hide Info");
    }
  }) 
}
            
          
!
999px
Loading ..................

Console