Skip to content

Instantly share code, notes, and snippets.

@bramus
Created April 22, 2022 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramus/3a3759d2bd63ff7e70cf8036349f45d2 to your computer and use it in GitHub Desktop.
Save bramus/3a3759d2bd63ff7e70cf8036349f45d2 to your computer and use it in GitHub Desktop.
Generate CSS @scroll-timeline definitions
// 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