Last active
December 20, 2016 23:46
-
-
Save brayhoward/5ef9546fb498b2ccedd6 to your computer and use it in GitHub Desktop.
Pure css parallax scrolling effect Sass mixin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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