Skip to content

Instantly share code, notes, and snippets.

@brayhoward
Last active December 20, 2016 23:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brayhoward/5ef9546fb498b2ccedd6 to your computer and use it in GitHub Desktop.
Save brayhoward/5ef9546fb498b2ccedd6 to your computer and use it in GitHub Desktop.
Pure css parallax scrolling effect Sass mixin.
@mixin parallax-scrolling($px, $scale) {
.parallax {
perspective: 1px;
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
}
.parallax-layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax-front {
transform: translateZ(0);
}
.parallax-back {
// translateZ needs to be a negative pixel value (-1px)
// The scale factor can be calculated with 1 + (translateZ * -1) / perspective
// transform: translateZ(-1) scale(2);
transform: translateZ($px) scale($scale);
}
}
.parallax
#particles-js.parallax-layer.parallax-back
#top-layer.parallax-layer.parallax-front
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment