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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <div class="card">
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	<div class="cell"></div>
	
	<div class="glare"></div>
	
	
	<div class="poster">
		<div class="poster__layer"></div>
		<div class="poster__layer"></div>
		<div class="poster__layer"></div>
		<div class="poster__layer"></div>
		<div class="poster__layer"></div>
	</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:900');
$n: 20;
$PI: 3.141592653589793;

@function number($value) {
  @if type-of($value) == 'number' {
    @return $value;
  } @else if type-of($value) != 'string' {
    $_: log('Value for `to-number` should be a number or a string.');
  }
  
  $result: 0;
  $digits: 0;
  $minus: str-slice($value, 1, 1) == '-';
  $numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9);
  
  @for $i from if($minus, 2, 1) through str-length($value) {
    $character: str-slice($value, $i, $i);
    
    @if not (index(map-keys($numbers), $character) or $character == '.') {
      @return to-length(if($minus, -$result, $result), str-slice($value, $i))
    }
    
    @if $character == '.' {
      $digits: 1; 
    } @else if $digits == 0 {
      $result: $result * 10 + map-get($numbers, $character);  
    } @else {
      $digits: $digits * 10;
      $result: $result + map-get($numbers, $character) / $digits;
    }
  }
  
  @return if($minus, -$result, $result);;
}

@function getCellPos($pos, $getter: false) {
	$q: $n;
	$p: $pos / $q;

	$decimalIndexInP: str-index('#{$p}', '.');
	
	$row: 0;
	$col: 0;
	
	@if $decimalIndexInP {
		$col: number(str-slice('#{$p}', $decimalIndexInP)) * $q;
		$row: floor($pos / $q) + 1;
	} @else {
		$col: $q;
		$row: floor($pos / $q);
	}
	
	@if $getter {
		@return round($col);	
	} @else {
		@return $row;
	}
}

@function linearRangeInterpolation($x1, $x2, $x3, $y1, $y3) {
	@return ((($x2 - $x1) * ($y3 - $y1)) / ($x3 - $x1)) + $y1;
}

@function atan ($x) {
	$i: 24;
	$sgn: 0;
	$a: 0;
	@if $x > 1 {
		$sgn: 1;
		$x: 1 / $x;
	} @else if $x < -1 {
		$sgn: -1;
		$x: 1 / $x;
	}
	@while $i > 0 {
		$a: ($i * $i * $x * $x) / (2 * $i + 1 + $a);
		$i: $i - 1;
	}
	@if $sgn > 0 {
		@return $PI / 2 - $x / (1 + $a);
	} @else if $sgn < 0 {
		@return -$PI / 2 - $x / (1 + $a);
	} @else {
		@return $x / (1 + $a);
	}
}

@function atan2 ($y, $x) {
	@if $x > 0 {
		@return atan($y / $x);
	} @else if $x < 0 {
		@if $y < 0 {
			@return atan($y / $x) - $PI;
		} @else {
			@return atan($y / $x) + $PI;
		}
	} @else {
		@if $y < 0 {
			@return - $PI / 2;
		} @else if $y > 0 {
			@return $PI / 2;
		} @else {
			@if 1 / $x == 1 / 0 {
				@return 0;
			} @else {
				@if 1 / $y == 1 / 0 {
					@return $PI;
				} @else {
					@return -$PI;
				}
			}
		}
	}
}


$layer1: 'https://designmodo.com/demo/apple-tv-parallax/images/1.png';
$layer2: 'https://designmodo.com/demo/apple-tv-parallax/images/2.png';
$layer3: 'https://designmodo.com/demo/apple-tv-parallax/images/3.png';
$layer4: 'https://designmodo.com/demo/apple-tv-parallax/images/4.png';
$layer5: 'https://designmodo.com/demo/apple-tv-parallax/images/5.png';

$layers: $layer1, $layer2, $layer3, $layer4, $layer5; 

*, *:before, *:after {
	box-sizing: border-box;
	position: relative;
}

html, body {
	width: 100%; height: 100%;
	
	margin: 0; padding: 0;
	
	display: flex;
	align-items: center;
	justify-content: center;
	
	background-color: #eee;
}

.card {
	width: 320px; height: 512px;
}

.cell {
	width: calc(100% / #{$n}); height: calc(100% / #{$n});
	
	position: absolute;
	
	z-index: 2;
	
	@for $i from 1 through 400 {
		
		&:nth-child(#{$i}) {
			$col: getCellPos($i, true);
			$row: getCellPos($i);
			
			left: calc(#{$col} * calc(100% / #{$n}) - calc(100% / #{$n}));
			top: calc(#{$row} * calc(100% / #{$n}) - calc(100% / #{$n}));
			
			&:hover ~ .poster {
				
				$sx: linearRangeInterpolation(1, $col, $n, 45, -45) + px;
				$sy: linearRangeInterpolation(1, $row, $n, 90, 0) + px;
				$ry: linearRangeInterpolation(1, $col, $n, -15, 15) + deg;
				$rx: linearRangeInterpolation(1, $row, $n, 15, -15) + deg;
				
				--sx: #{$sx};
				--sy: #{$sy};
				--ry: #{$ry};
				--rx: #{$rx};
			}
			
// 				GLARE WIP
			
// 			&:hover ~ .poster:after {
// 				$grediantPos: 0;
// 				$angle: 0 + deg;
				
// 				@if $col <= $n / 2 {
// 					$grediantPos: linearRangeInterpolation(1, $col, $n, 40, 0) + '%';	
// 				} @else {
// 					$grediantPos: linearRangeInterpolation(1, $col, $n, 0, 40) + '%';	
// 				}
				

// 				$angle: (15 * $col) + (15 * $row) + deg;
				
// 				background: linear-gradient($angle, rgba(white, .5) 0%, rgba(white, 0) #{$grediantPos});
// 			}
			
			
// 			FOR WHATEVER REASON CUSTOM PROPERTIES ARE REALLY SLOW FOR THIS AND UPDATING THE STYLES INSTEAD WHICH STILL CREATES LAG, SO COMMENTING OUT THE OTHER ONES, BECAUSE UPDATING ONLY ONE LAYER WORKS. K_TODO = FIGURE OUT HOW TO GET ALL LAYERS TO BE SMOOTH, THE ANSWER OBVIOUSLY ISN'T TRANSLATE, EVEN IF IT'S 3D
			
// 			&:hover ~ .poster > .poster__layer:nth-child(1) {
// 				$bgx: linearRangeInterpolation(1, $col, $n, 20, -20) + px;
// 				$bgy: linearRangeInterpolation(1, $row, $n, 20, -20) + px;
				
// 				transform: translate3d($bgx, $bgy, 0px);
// 			}
			
// 			&:hover ~ .poster > .poster__layer:nth-child(2) {
// 				$bgx: linearRangeInterpolation(1, $col, $n, 10, -10) + px;
// 				$bgy: linearRangeInterpolation(1, $row, $n, 10, -10) + px;
				
// 				transform: translate3d($bgx, $bgy, 0px);
// 			}
			
// 			&:hover ~ .poster > .poster__layer:nth-child(3) {
// 				$bgx: linearRangeInterpolation(1, $col, $n, 10, -10) + px;
// 				$bgy: linearRangeInterpolation(1, $row, $n, 10, -10) + px;
				
// 				transform: translate3d($bgx, $bgy, 0px);
// 			}
			
			
			&:hover ~ .poster > .poster__layer:nth-child(5) {
				$bgx: linearRangeInterpolation(1, $col, $n, -10, 10) + px;
				$bgy: linearRangeInterpolation(1, $row, $n, 10, -10) + px;
				
				transform: translate3d($bgx, $bgy, 0px);
			}
		}
	}
}

.poster {
	--sx: 0;
	--sy: 45px;
	--rx: 0deg;
	--ry: 0deg;
	
	overflow: hidden;
	width: 100%; height: 100%;
	
	border-radius: 5px;
	box-shadow: var(--sx) var(--sy) 100px rgba(0, 0, 0, .4);
	
	transform: perspective(1000px) rotateX(var(--rx)) rotateY(var(--ry)) rotateZ(0deg);
	
	// no need to apply transition to box-shadow, since the blurriness already creates transition effect
	transition: transform .15s linear;
	
	will-change: transform, box-shadow;
	
	&:after {
		width: 100%; height: 100%;
	
		left: 0; top: 0;
		position: absolute;

		background: linear-gradient(0deg, rgba(red, 1) 0%, rgba(red, 0) 0%);
		content: '';

		pointer-events: none;
		z-index: 3;
	}
}

.poster__layer {
	--bgx: 0%;
	--bgy: 0%;
	
	width: 110%; height: 110%;
		
	left: -5%; top: 0%;
	position: absolute;
	
	background-repeat: no-repeat;
	background-size: 100% 100%;
	
	transform: translate3d(var(--bgx), var(--bgy), 0px);
	transition: .1s ease; // having a transition works if animating one layer, when animating more, shit becomes unbearably laggy
	will-change: transform;
	
	@for $i from 1 through 5 {
		&:nth-child(#{$i}) {
			background-image: url(nth($layers, $i));
		}
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console