2

I'm attempting to implement Parallax Scrolling using CSS Perspective, but Safari applies negative transforms differently from Chrome and Firefox.

Here is an image showing the issue. Left is Safari, right is Firefox

The intended behavior is that of Firefox. Chrome works exactly as Firefox does.

Here is the jsfiddle showing the issue

<body>
  <div class="parallax_root">
    <div class="prlx back_cat">
      <img src="http://lorempixel.com/200/800/cats/">
    </div>
    <div class="prlx front_food">
      <img src="http://lorempixel.com/800/200/food/">
    </div>
  </div>
</body>
.parallax_root {
  height: 100vh;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-perspective: 1px;
  perspective: 1px;
}

.prlx {
  position: absolute;
}

.back_cat {
  transform: translateZ(-1px);
}

.front_food {
  transform: translateZ(-2px);
}

Is there any way of achieving the correct parallax effect on Safari without breaking the functionality on other browsers, especially when taking into account multiple parallax layers?

Alex
  • 35
  • 5
  • Yeah, Safari always got it weird: https://stackoverflow.com/questions/18146511/bug-in-css3-rotatey-transition-on-safari https://stackoverflow.com/questions/5472802/css-z-index-lost-after-webkit-transform-translate3d?noredirect=1&lq=1 – Kaiido Jun 03 '19 at 01:52
  • I did see both of those but it doesn't look like either refers to perspective specifically (over Z-index) since I would like to have CSS-only scrolling. – Alex Jun 05 '19 at 04:00
  • I think the core of the issue is the same in all three cases: Safari stacks incorrectly 3D rendering contexts. – Kaiido Jun 05 '19 at 04:14
  • So what would be the correct solution in this case then, reverse the perspective values for webkit? – Alex Jun 05 '19 at 04:29
  • I unfortunately don't know, otherwise I would have answered already ;-) – Kaiido Jun 05 '19 at 04:46
  • 1
    Thanks for the help anyway @Kaiido ! I rephrased my question a bit so maybe someone who has dealt with the issue before could give some further insight. – Alex Jun 05 '19 at 04:51
  • Yes your question looks better now. I hope someone will have a solution for you, and if you do find one on your own, remember that you are welcome to self-answer your own question. – Kaiido Jun 05 '19 at 04:52
  • Facing the same issue. Did you get any solution for this? – tsfahmad Oct 19 '21 at 11:38

0 Answers0