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.

            
              <canvas></canvas>

<!-- Social -->
<div class="twitter social-icon">
  <a href="https://twitter.com/Christopher4Lis" target="_blank"></a>
  <i class="fa fa-twitter fa-lg"></i>
</div>

<div class="youtube social-icon">
  <a href="https://www.youtube.com/channel/UC9Yp2yz6-pwhQuPlIDV_mjA" target="_blank"></a>
  <i class="fa fa-youtube fa-lg"></i>
</div>
            
          
!
            
              body {
  overflow: hidden;
  background: black;
}

// Twitter
.twitter {
  &:hover {
    a {
      transform: rotate(-45deg) scale(1.05);
    }
    
    i {
      color: lighten(#00ACED, 10%);
    }
  }
  
  a {
    bottom: -40px;
    right: -75px;
    transform: rotate(-45deg);
  }
  
  i {
    bottom: 7px;
    right: 7px;
    color: #00ACED;
  }
}

.social-icon {
  a {
    position: absolute;
    background: white;
    color: white;
    box-shadow: -1px -1px 20px 0px rgba(0,0,0,0.30);
    display: inline-block;
    width: 150px;
    height: 80px;  
    transform-origin: 50% 50%;
    transition: .15s ease-out;
  }
  
  i {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
    transition: .15s ease-out;
  }
}

// YouTube 

.youtube {
  &:hover {
    a {
      transform: rotate(45deg) scale(1.05);
    }
    
    i {
      color: lighten(#E62117, 10%);
    }
  }
  
  a {
    bottom: -40px;
    left: -75px;
    transform: rotate(45deg);
  }
  
  i {
    bottom: 7px;
    left: 7px;
    color: #E62117;
  }
}
            
          
!
            
              var canvas = document.querySelector('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var c = canvas.getContext('2d');
var mouse = {x: undefined, y: undefined};
var maxPullDistance = canvas.height * 0.8;

window.addEventListener("mousemove", function(e) {
	mouse.x = e.clientX;
	mouse.y = e.clientY;
});

window.addEventListener("resize", function(e) {
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;

	createBars();
});

function Bar(x, width, delay) {
	this.position = {x: x, y: canvas.height};
	this.width = width;
	this.timer = delay;
	this.height = 0;

	this.update = function() {
		this.timer += 0.01;

		var distanceBetweenBarAndMouse = {
			x: ((this.position.x + this.width / 2) - mouse.x),
			y: this.position.y - this.height - mouse.y
		};

		if (distanceBetweenBarAndMouse.y < maxPullDistance &&  distanceBetweenBarAndMouse.x > -this.width / 2 && distanceBetweenBarAndMouse.x < this.width / 2) {
			this.height += ((this.position.y - this.height) - mouse.y) * 0.12;
		} else if (distanceBetweenBarAndMouse.y < maxPullDistance && distanceBetweenBarAndMouse.x > -this.width * 1.5 && distanceBetweenBarAndMouse.x < this.width * 1.5) {
			this.height += ((this.position.y - this.height) - mouse.y) * 0.01;
		} else {
			var maxBarHeightWithSin = canvas.height / 3;

			// Smooth animation down to original height
			this.height -= (this.height - Math.abs(Math.sin(this.timer) * canvas.height / 2.5)) * 0.12;

		}
		this.draw();
	}

	this.draw = function() {
		// Change hue of bar gradually from 1 to 255 and then back from 255 to 1
		c.fillStyle = 'hsl('+Math.abs(Math.sin(this.timer) * 255)+', 50%, 50%)';
		c.fillRect(this.position.x ,canvas.height - this.height, this.width, this.height);
	}	
}

var bars;
var barCount;
var barWidth;
var barPosition;
var barDelay;

function createBars() {
	bars = [];
	barCount = 15;
	barWidth = canvas.width / barCount;
	barPosition = 0;
	barDelay = 0;

	for (var i = 0; i < barCount; i++) {
		bars.push(new Bar(barPosition, barWidth, barDelay));
		barPosition += barWidth;
		barDelay += 0.2;
	}
}

function animate() {
	window.requestAnimationFrame(animate);
	c.fillStyle = 'rgba(0,0,0,0.1)';
	c.fillRect(0, 0, canvas.width, canvas.height);

	bars.forEach(function(bar) {
		bar.update();
	});
}

createBars();
animate();
            
          
!
999px
Loading ..................

Console