From 1d00bf96e453d1fefaa6d68b33e1f96a61a81861 Mon Sep 17 00:00:00 2001 From: ADTC Date: Sun, 16 Mar 2025 10:11:01 +0000 Subject: [PATCH 1/6] Add installation steps, known limitations to README Also do some formatting, add more links, and fix language issues for existing parts of the README. --- README.md | 201 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 160 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index cd3c5db..c9e8cf1 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,203 @@ -# Scroll-timeline Polyfill +# Scroll-timeline Polyfill for Scroll-driven Animations -A polyfill of ScrollTimeline and ViewTimeline as defined by the [spec](https://drafts.csswg.org/scroll-animations-1/). +A polyfill of ScrollTimeline and ViewTimeline as defined by [the CSS WG spec](https://drafts.csswg.org/scroll-animations-1/). -View a [cool demo showing its usage](https://flackr.github.io/scroll-timeline/demo/parallax/)! +- [View a cool demo showing its usage.](https://flackr.github.io/scroll-timeline/demo/parallax/) +- [Track the browser support for native Scroll-driven Animations.](https://caniuse.com/?search=animation-timeline) -# Usage +When the scroll-driven animations feature is widely available as a native feature, this polyfill may not be necessary except to support older versions of browsers. -To use this polyfill, import the module into your site and you can start creating animations that use a `ScrollTimeline` or `ViewTimeline`. +## Installation + +Use one of these methods to add the polyfill and it should begin working immediately. If it's not working, see the [_Known Limitations_](#known-limitations) section. + +### [NPM package](https://www.npmjs.com/package/scroll-timeline-polyfill) + +```sh +npm install scroll-timeline-polyfill +``` + +You may also use `pnpm` or `yarn`. Once installed, import it: ```js -import 'https://flackr.github.io/scroll-timeline/dist/scroll-timeline.js'; +import "scroll-timeline-polyfill/dist/scroll-timeline.js"; +``` -document.getElementById('parallax').animate( - { transform: ['translateY(0)', 'translateY(100px)']}, - { fill: 'both', - timeline: new ScrollTimeline({ - source: document.documentElement, - }), - rangeStart: new CSSUnitValue(0, 'px'), - rangeEnd: new CSSUnitValue(200, 'px'), - }); +### JavaScript import (CDN) + +```js +import "https://flackr.github.io/scroll-timeline/dist/scroll-timeline.js"; ``` -Also works with CSS Animations that use a `view-timeline` or `scroll-timeline` +### HTML script tag (CDN) ```html ``` +## Usage + +To use this polyfill, start creating animations using CSS or JavaScript. + +### JavaScript usage + +Use a `ScrollTimeline` or `ViewTimeline` instance to define animations. + +```js +document.getElementById("parallax").animate( + { transform: ["translateY(0)", "translateY(100px)"] }, + { + fill: "both", + timeline: new ScrollTimeline({ + source: document.documentElement, + }), + rangeStart: new CSSUnitValue(0, "px"), + rangeEnd: new CSSUnitValue(200, "px"), + } +); +``` + +### CSS usage + +Use `animation-timeline` property with `scroll` or `view` to define animations: + ```css @keyframes parallax-effect { - to { transform: translateY(100px) } + to { + transform: translateY(100px); + } } -#parallax { +.parallax { animation: parallax-effect linear both; animation-timeline: scroll(block root); animation-range: 0px 200px; } ``` -Please ensure your CSS is hosted on the same domain as your website or included directly on the page within a