CSS-Native Parallax Effect

(dan-webnotes.com)

42 points | by dandep 1 hour ago

8 comments

  • mpeg 1 hour ago
    How does this compare to the classic css-native parallax effect? Before the scroll timeline APIs you'd use the "perspective" css property to create a container where the z plane is n pixels away from the screen, and then position each layer within it at a different z distance using transform: translateZ

    That method is GPU accelerated too, so it is performant compared to some js solutions, and has worked well in every browser for around a decade

    I like the idea of the scroll-timeline though, just keen to understand what the advantage is for this

    • som 31 minutes ago
      No doubt quite a few folk with the same question. Keen to understand performance tradeoffs.

      Obvious comparison note would be that the "new" method currently enjoys somewhat limited browser support (no Firefox without a flag, and only since Safari 26)

    • iainmerrick 59 minutes ago
      I was wondering the same thing. That translateZ is a bit fiddly to get right, so I could believe this is a bit easier to use, maybe? And presumably this could be used for other properties besides position, like colors, opacity or blurs.
  • phelm 1 hour ago
    • frereubu 1 hour ago
      There's me scrolling up and down and thinking "hey, it's not working!" But it's behind a flag on Firefox: https://caniuse.com/?search=view-timeline-name
      • wnevets 7 minutes ago
        Doesnt work on any browser for me
      • WithinReason 50 minutes ago
        tried 4 browsers, didn't work in any of them
        • alpinisme 33 minutes ago
          FWIW it works on iPhone safari
      • werdnapk 53 minutes ago
        It's been behind a flag for ages. Maybe because of performance issues?
      • anssip 1 hour ago
        Noticed the same thing. In Mac Safari it works without setting any flags.
    • Mashimo 40 minutes ago
      Only worked for me on mobile (vivaldi android) not on vivaldi / chrome / edge on Desktop.
    • account42 1 hour ago
      What an age where we need a pile of javascript as well as a bot check to demo a simple CSS trick.
      • zamadatix 16 minutes ago
        The JS and bot check are for making additional functionality, beyond just showing the example, work easily. I.e. editing and sharing edits from a browser. If all you want is a static example, feel free to make it without these things.
  • baliex 1 hour ago
    That sounds interesting but it would be a whole lot more interesting if the page was itself an example of said effect!
    • dsmurrell 0 minutes ago
      I was also looking for examples.
  • thomasikzelf 52 minutes ago
    You can make some really cool stuff with css scroll animations. I used SVG paths with a scroll animated dash offset to draw an image while scrolling. Zero javascript, it feels so smooth. https://thomaswelter.nl (the background)
    • rsyring 5 minutes ago
      Android Firefox: there is no background image.
  • duskdozer 48 minutes ago
    In a world where it's increasingly overlooked, I'm glad the author mentions disabling it respecting user settings. I do think it should be reversed and only enabled with the `@media (prefers-reduced-motion: no-preference)`, but that is the opinion of someone who gets negative value from animations and is bemused by how much dev and compute time is spent on them.
  • sillyboi 31 minutes ago
    It would be awesome to put an interactive example right in the article.
  • rohitsriram 51 minutes ago
    Love the one-variable design where scale and translate stay in sync automatically, just wish Firefox would get off the flag already.
  • xuzhenpeng 27 minutes ago
    [flagged]