Created
April 22, 2022 23:14
-
-
Save bramus/3a3759d2bd63ff7e70cf8036349f45d2 to your computer and use it in GitHub Desktop.
Generate CSS @scroll-timeline definitions
This file contains 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
// Code that generates the CSS Scroll-Timelines for https://codepen.io/bramus/pen/xxRZZdK | |
const generateCSS = () => { | |
let css = ''; | |
document.querySelectorAll('li').forEach((li, i) => { | |
const id = li.getAttribute('id'); | |
css = ` | |
${css} | |
@scroll-timeline scroll-in-cards-${id} { | |
source: selector(#cards); | |
orientation: inline; | |
start: selector(#${id}) end 0; | |
end: selector(#${id}) start 0; | |
scroll-offsets: | |
selector(#${id}) end 0, | |
selector(#${id}) start 0 | |
; | |
} | |
/* Adjust the li on scroll (z-index) */ | |
#${id} { | |
animation-timeline: scroll-in-cards-${id}; | |
} | |
/* Adjust the album cover on scroll (perspective) */ | |
#${id} > img { | |
animation-timeline: scroll-in-cards-${id}; | |
} | |
`; | |
}); | |
return css; | |
} | |
const injectCSS = (css) => { | |
const style = document.createElement('style'); | |
style.innerHTML = css; | |
document.head.appendChild(style); | |
} | |
console.log(generateCSS()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment