Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <link rel="stylesheet" href="animate.min.css">
<script type="application/javascript" src="https://jsonip.appspot.com/?callback=getip"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 

<canvas id="canvas"></canvas>
<canvas id="cloud-canvas"></canvas>

<div class="but animated fadeInDown top">
  <button class="btn get-weather inp">Get Current Weather</button>
  <p class="or inp"><br> - OR - <br></p>
  <input class="zip inp" type="text" name="" placeholder="ZIP Code">
  <button class="btn get-zip inp">Get Using Zip Code</button>
  <p class="or cheat inp"><br> - OR - <br></p>
  <button class="btn make rain cheat">Make it rain</button>
  <button class="btn make snow cheat">Make it snow</button>
</div>


<div class="temp">
  <button class="temp-btn tempa inp" id="temper"></button>
  <div class="summary tempa inp"></div>
  <div class="location tempa inp">  </div>
</div>
<div class="tag">Page by Andrew Wagner, 2016 
  <a href="https://darksky.net/poweredby/" target="_blank"> powered by Dark Sky</a>
</div>
              
            
!

CSS

              
                .but {
  text-align: center;
  position: fixed;
  width: 100%;
  top: 40px;

}
.tag {
  bottom: 0;
  position: fixed;
  right: 0;
  margin: auto;
  padding: 10px;
  background: #FFF;
  opacity: .15;
  -webkit-transition: all .5s ease;
  border-radius: 4px 0 0 0
}
.tag:hover {
  opacity: .6;
}

.get-weather, .get-zip, .make{
  
  background: #359;
  color: #FFF;
}

.btn-box {
    margin: auto;
  text-align: center;
}

.summary {
  font-size: 200%;
}

.temp {
  position: absolute;
  width: 100%;
  top: 260px;
  text-align: center;
  color: #FFF;
  opacity: 0;
  -webkit-transition: all 1s ease;
  z-index: 5;
}

.or {
  color: #CCC;
  font-weight: bold;
}

.inp {
  -webkit-transition:opacity 1s ease;
}

.temp-btn {
  font-size: 500%;
  color: #FFF;
  opacity: 0;
  z-index: 5 ! important;
  -webkit-transition: all 1s ease;
  background: none;
}

.tempa:focus {
    outline: none;
}

.tempa:focus, input:focus{
  outline: none;
  background: none;
}

.tempa {
  opacity: 0;
  -webkit-transition: all 1s ease;
}


.zip {
  margin: 0px auto 20px auto;
  width: 200px;
}

html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  background-repeat: no-repeat;
  background-attachment: fixed;
	background: #6b92b9;
  -webkit-transition:all 1.5s ease
}

#canvas {
  position: fixed;
	display: block;
  -webkit-transition: all 1s ease;
  z-index: 0 ! important;
  top: 80px;
}
              
            
!

JS

              
                var jsonResp;
var temp = 0;
var faren = true;
var summary = "";
var day = true;
var skyColor = "Sunny";
var animate = false;
var inter
var inter2

$(document).ready(function() {
  $(".rain").click(function() {
    clearCanvas();
    day = false
    clouds(20, 1);
    rain(20, .9);
    skyColor = "Night";
    sky(skyColor);
  });
  
  $(".snow").click(function() {
    clearCanvas();
    day = false
    clouds(5, 1);
    snow(5, .9);
    skyColor = "Night";
    sky(skyColor);
  });
  
  $(".get-zip").click(function() {
    $(".cheat").remove();
    faren = true;
    var n = $(".zip").val()
    if (!isNaN(parseFloat(n)) && isFinite(n) && n.length == 5){
      getZip(n);
    } else {
      alert("Invalid ZIP Code");
    };
  });
  
  $(".get-weather").click(function(){
    $(".cheat").remove();
    faren = true;
    $.get("http://ipinfo.io", function (response) {
      useLoc(response.loc);
    }, "jsonp");  
  });
  
  $(".temp-btn").click(function() {
    if (faren) {
      temp = (temp - 32) * 5 / 9;
      faren = false;
      $(".temp-btn").html(Math.floor(temp) + "&#8451");
      $(".cels").html("&#8457");
    } else {
      temp = temp * 9 / 5 + 32;
      faren = true;
      $(".temp-btn").html(Math.floor(temp) + "&#8457");
      $(".cels").html("&#8451");
    }
  });
  clouds(5, .3);
});

function clearCanvas() {
  clearInterval(inter);
  clearInterval(inter2);
  var canvas = document.getElementById("canvas");
  var ctx = canvas.getContext("2d");

  //canvas dimensions
  var W = window.innerWidth;
  var H = window.innerHeight;
  canvas.width = W;
  canvas.height = H;
  ctx.clearRect(0, 0, W, H);
}

function getZip(n) {
  var gKey = "AIzaSyAOF_PkA7OXeRBYkDHqfz4KeDwSBcSmcO4"
  var gAPI = "https://maps.googleapis.com/maps/api/geocode/json?address="
  gAPI += n + "&key=" + gKey
  
  $.get(gAPI, function (response){
    if (response.status == "ZERO_RESULTS") {
      alert("Invalid ZIP Code")
    } else {
      try {
        var corners = response.results[0].geometry.bounds
        var lat = (corners.northeast.lat + corners.southwest.lat) / 2;
        var lng = (corners.northeast.lng + corners.southwest.lng) / 2;
      } catch(err) {
        var spot = response.results[0].geometry.location
        var lat = spot.lat
        var lng = spot.lng
      }
      useLoc(lat.toFixed(4) + "," + lng.toFixed(4));
    };
  });
};

function useLoc(loc) {
  //set up weather api call
  apiKey = "a3b1d0770e77e8966324ad072fddf620"
  apiCall = "https://api.darksky.net/forecast/" + apiKey;
  apiCall += "/" + loc;
  var place = getPlace(loc);
  $.get(apiCall, function (weather) {
    temp = Math.round(weather.currently.temperature);
    $(".tempa").css("opacity", 1);
    $(".temp-btn").html(temp + "&#8457");
    process(weather);
  }, "jsonp");
}

function getPlace(loc) {
  var gKey = "AIzaSyAOF_PkA7OXeRBYkDHqfz4KeDwSBcSmcO4"
  var gAPI = "https://maps.googleapis.com/maps/api/geocode/json?latlng="
  gAPI += loc + "&key=" + gKey
  $.get(gAPI, function (response) {
    var cityState = response.results[0].formatted_address;
    var cs = cityState.split(",");
    cityState = cs[1] + "," + cs[2];
    $(".location").text(cityState)
    $(".location").text(response.results[0].formatted_address)
  });
}

function process(weather){
  var icon = weather.currently.icon;
  var cc = weather.currently.cloudCover;
  var rise = weather.daily.data[0].sunriseTime;
  var set = weather.daily.data[0].sunsetTime;
  var now = weather.currently.time;
  var wind = weather.currently.windSpeed;
  var precip = weather.currently.precipIntensity;
  animate = false;
  if (rise < now && now < set) {
    day = true;
    if (cc > .7) {
      skyColor = "Cloudy";
    } else {
      skyColor = "Sunny";
    }
  } else {
    day = false;
    skyColor = "Night";
  }
  $(".inp").css("opacity", .5);
  $("#toggle").addClass("cels");
  $(".tempa").css("opacity", .9);
  $(".temp").css("opacity", .9);
  
  sky(skyColor);
  clearCanvas()
  clouds(wind, cc);
  $(".summary").html(weather.currently.summary);
  switch(icon)
      {
    case "clear-day":
    case "clear-night":
    case "rain":
      rain(wind, precip);
      break;
    case "snow":
      snow(wind, precip);
      break;
    case "sleet":
      rain(wind, precip);
      break;
    case "wind":
    case "fog":
    case "cloudy":
    case "partly-cloudy-day":
    case "partly-cloudy-night":
    default:
      break;
  }
}

sky = function(color){
  switch(color)
      {
    case "Sunny":
      $("body").css({ background:"-webkit-gradient(linear, left top, left bottom, from(#6b92b9), to(#3b6299))" 
                    });
      break;
    case "Night":
      $("body").css({background: "-webkit-gradient(linear, left top, left bottom, from(#080320), to(#010003))" 
                    });
      break;
    case "Cloudy":
      $("body").css({ background: "-webkit-gradient(linear, left top, left bottom, from(#ccc), to(#888))" 
                    });
      break;
  }
}


snow = function(windSpeed, dens){
  //canvas init
  var canvas = document.getElementById("canvas");
  var ctx = canvas.getContext("2d");

  //canvas dimensions
  var W = window.innerWidth;
  var H = window.innerHeight;
  var dx = 0;
  var dy = 0;
  canvas.width = W;
  canvas.height = H;

  //snowflake particles
  var mp = W * dens / 3; //max particles
  var particles = [];
  for(var i = 0; i < mp; i++)
  {
    particles.push({
      x: Math.random()*W, //x-coordinate
      y: Math.random()*H, //y-coordinate
      r: Math.random()*3+1, //radius
      d: Math.random()*mp, //density
      dx: 0,
      dy: 0,
      w: windSpeed/240 * 6.28 //windSpeed
    })
  }

  function draw()
  {
    W = window.innerWidth;
    H = window.innerHeight;
    canvas.width = W;
    canvas.height = H;
    ctx.clearRect(0, 0, W, H);
    if (skyColor === "Night") {
      ctx.fillStyle = "rgba(190, 199, 200, 0.8)";
    } else {
      ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
    }
    ctx.beginPath();
    for(var i = 0; i < mp; i++)
    {
      var p = particles[i];
      ctx.moveTo(p.x, p.y);
      ctx.arc(p.x, p.y, p.r, 0, Math.PI*2, true);
    }
    ctx.fill();
    update();
  }
  function update()
  {
    dy += (Math.random() - .5) / 10;
    dy = Math.min(dy, 1);
    dy = Math.max(dy, -.3);
    dx += (Math.random() - .5) / 10;
    dx = Math.min(dx, .5);
    dx = Math.max(dx, -.1);
    for(var i = 0; i < mp; i++)
    {
      var p = particles[i];
      p.dy += (Math.random() - .49) / 10;
      p.dy = Math.min(p.dy, .2);
      p.dy = Math.max(p.dy, -.1);
      p.dx += (Math.random() - .5) / 10;
      p.dx = Math.min(p.dx, .1);
      p.dx = Math.max(p.dx, -.1);
      p.y = (p.y + Math.cos(p.w) + dy + p.dy) % H;
      
      p.x = (p.x + Math.sin(p.w) * 8 + dx + p.dx) % W;
    }
  }

  //animation loop
 inter = setInterval(draw, 30);
}

rain = function(windSpeed, dens){
  //canvas init

  var canvas = document.getElementById("canvas");
  var ctx = canvas.getContext("2d");

  //canvas dimensions
  var W = window.innerWidth;
  var H = window.innerHeight;
  canvas.width = W;
  canvas.height = H;
  
  var mp = W/6 * dens; //max particles
  var particles = [];
  for(var i = 0; i < mp; i++)
  {
    particles.push({
      x: Math.random()*W, //x-coordinate
      y: Math.random()*H, //y-coordinate
      r: Math.random()*3+1, //radius
      dx: 0,
      dy: 0,
      w: windSpeed/240 * 6.28 //windSpeed
    })
  }

  function draw()
  {
    ctx.clearRect(0, 0, W, H);

    if (skyColor === "Night") {
      ctx.strokeStyle="rgba(255, 255, 255, 0.01)";
    } else {
      ctx.strokeStyle="rgba(255, 255, 255, 0.5)";
    }
    ctx.beginPath();
    for(var i = 0; i < mp; i++)
    {
      var p = particles[i];
      ctx.moveTo(p.x + 2*p.w, p.y + 30);
      ctx.lineTo(p.x - 2*p.w, p.y - 30);
      ctx.stroke();
    }
    ctx.fill();
    update();
  }
  function update()
  {
    for(var i = 0; i < mp; i++)
    {

      var p = particles[i];
      p.y = (p.y + Math.cos(p.w) + p.r/2 + 20) % H;
      var dx = Math.sin(p.w)
      p.x = (p.x + Math.abs(dx) * 8 + p.dx);
      if (p.y > H){
        p.y = 0;
        p.x = Math.random() * W;
      }
      if (p.x > W){
        p.x = 0
      }
    }
  }

  //animation loop
  inter = setInterval(draw, 30);
}

clouds = function(windSpeed, dens){
  var canvas1 = document.getElementById("cloud-canvas");
  var ctx1 = canvas1.getContext("2d");

  //canvas dimensions
  var W = window.innerWidth;
  var H = window.innerHeight;
  canvas1.width = W;
  canvas1.height = 200;

  var mp = dens * 40 ; 
  var particles = [];
  for(var i = 0; i < mp; i++)
  {
    particles.push({
      x: i * W/34, //x-coordinate
      y: Math.random() * 40, //y-coordinate
      r: Math.random() * W/50  + W/50 + 25, //radius
      d: Math.random(), //density
      dx: 0,
      dy: 0,
      w: windSpeed/240 * 4 //windSpeed
    })
  }
  var theta = 0;
  function draw()
  {
    if (!animate){
      clearInterval(draw);
    }
    theta += .03;
    var sunsize = 40 + Math.cos(theta) * 2
    ctx1.clearRect(0, 0, W, H);
    ctx1.beginPath();
    if (skyColor=="Sunny" && day){
      ctx1.fillStyle = "rgba(255, 255, 0, .9)"
      ctx1.arc(0, 0, sunsize, 0, Math.PI*2, true);
      ctx1.fill();
    }
   
    
    for(var i = 0; i < mp; i++)
    {
      ctx1.beginPath()
      var p = particles[i];
      var cloudColor
      if (skyColor == "Night") {
        cloudColor = 150 + p.d * 10
      } else {
        cloudColor = 235 + p.d * 15;
      }
      cloudColor = Math.floor(cloudColor);
      ctx1.fillStyle = "rgba("+ cloudColor +","+ cloudColor +","+ cloudColor +", .95)";
      ctx1.moveTo(p.x, p.y);
      ctx1.arc(p.x, p.y, p.r, 0, Math.PI*2, true);
      ctx1.fill();
    }
    update();
  }
  function update()
  {
    for(var i = 0; i < mp; i++)
    {
      var p = particles[i];
      p.dy += (Math.random() - .49) / 20;
      p.dy = Math.min(p.dy, .5);
      p.dy = Math.max(p.dy, -.5);
      p.y += p.dy
      p.y = Math.min(p.y, 40);
      p.y = Math.max(p.y, 0);
      if (p.y == 0 || p.y == 40){
        p.dy == 0;
      };
      var dx = Math.sin(p.w)
      p.x = (p.x + Math.abs(dx) * 4 + p.dx) % (W + 80);
      if (p.x > W + 75) {
        p.x = -80;
      }
    }
  }
  
  //animation loop
  inter2 = setInterval(draw, 33);
  
  
}
              
            
!
999px

Console