Skip to content

Instantly share code, notes, and snippets.

@RussellHite
Last active October 11, 2017 14:15
Show Gist options
  • Save RussellHite/9d1a4f85a3d689dbca003f86cd10cd10 to your computer and use it in GitHub Desktop.
Save RussellHite/9d1a4f85a3d689dbca003f86cd10cd10 to your computer and use it in GitHub Desktop.
MX partial for creating paralax with just css
/* Parallax base styles
--------------------------------------------- */
// Refer to http://keithclark.co.uk/articles/pure-css-parallax-websites/ for more details
.parallax {
height: 500px; /* fallback for older browsers */
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
-webkit-perspective: 300px;
perspective: 300px;
}
.parallax__group {
position: relative;
height: 500px; /* fallback for older browsers */
height: 100vh;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.parallax__layer {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
// for every class that has translateZ on it you will need to calculate the scale, use this calculation:
// 1 + (translateZ * -1) / perspective
.parallax__layer--fore {
-webkit-transform: translateZ(90px) scale(.7);
transform: translateZ(90px) scale(.7);
z-index: 1;
}
.parallax__layer--base {
-webkit-transform: translateZ(0);
transform: translateZ(0);
z-index: 4;
}
.parallax__layer--back {
-webkit-transform: translateZ(-300px) scale(2);
transform: translateZ(-300px) scale(2);
z-index: 3;
}
.parallax__layer--deep {
-webkit-transform: translateZ(-600px) scale(3);
transform: translateZ(-600px) scale(3);
z-index: 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment