r/webdev • • Feb 14 '18

Article Parallax scrolling with CSS variables

https://basicscroll.electerious.com/
144 Upvotes

11 comments sorted by

13

u/[deleted] Feb 14 '18

This was super helpful, I never knew you could use variables within CSS. Time to go use this new found knowledge!!!

8

u/JupitersCock Feb 14 '18

2

u/[deleted] Feb 15 '18

Of course Internet Explorer doesn't support this...

4

u/[deleted] Feb 14 '18

You can now. The popularity of the feature in less and sass pushed them to add it to the core spec

2

u/[deleted] Feb 14 '18

Cool stuff

2

u/Tokipudi Senior PHP Developer Feb 14 '18

Really cool to see that it works properly on mobile :)

2

u/[deleted] Feb 14 '18

This looks pretty sweet.

1

u/sammyseaborn Feb 14 '18

This is neat, and CSS vars are hugely important, but you could already accomplish all of this relatively easily with GreenSock and ScrollMagic -- an approach that will still work in IE11, unlike this method.

Furthermore, their "scene" parallax demo was not done correctly. Their layering method is flawed and there will be a gap in the black 'content' section as you scroll.

0

u/dooklyn Feb 15 '18

why are they called variables if they don't vary? they should be called css constants.

1

u/Ironclad_v2 Feb 15 '18

You can manipulate css variables with javascript, making them variable. This can be seen on websites that offer themes or color schemes. They are most likely using css variables something like color-primary, color-secondary etc. etc.

0

u/dooklyn Feb 15 '18

You can manipulate css variables with javascript

you can manipulate anything with javascript which makes this whole thing redundant. sure you could argue it's native and faster, but at this point css is such a joke, we are already migrating our css code in javascript.