scroll - CSS multiple fixed background psuedo elements -
i trying create parallax scrolling effect using css , no third party libraries. using background-attachment: fixed
able achieve effect wanted on multiple full-width divs on page. using that, however, negatively impacted performance great deal. instead changed method 1 found here:
.element { overflow: hidden; // added pseudo-element position: relative; // added pseudo-element // fixed-position background image &::before { content: ' '; position: fixed; // instead of background-attachment width: 100%; height: 100%; top: 0; left: 0; background: url('/path/to/img.jpg') no-repeat center center; background-size: cover; will-change: transform; // creates new paint layer z-index: -1; } }
i used method on 1 div try out, , worked excellently. when applied rest, however, backgrounds overlapped, , ever saw 1 of them (since rest behind it). it's z-index issue since of pseudo elements overlapping, can't think of css solution.
unfortunately, not think parallax effect work on more 1 div. in working example, first image stays background whole page no matter div in. gets covered divs 1 , 2.
i take @ following link on making multiple div parallax effects:
hope helps!
Comments
Post a Comment