Skip to content

Commit 9071bd8

Browse files
committed
Ensure progress offsets are properly inverted
1 parent f6e8ac0 commit 9071bd8

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A tiny custom element for all your scrollytelling needs! The successor to [`@new
44

55
## Key features
66

7-
- 🐜 **Less than 700 bytes** brotli'ed, **less than 800 bytes** gzip'ed
7+
- 🐜 **~700 bytes** brotli'ed, **~800 bytes** gzip'ed
88
- 👀 Uses a highly-performant **[Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)** to monitor scrolling changes
99
- 📚 Smartly uses scroll events to **calculate scroll progress** only when needed
1010
- 🌻 Each `<scroll-scene>` element may **have its own** `offset` and **opt-in** to `progress` events

docs/progress.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</style>
7777
<script src="https://unpkg.com/scroll-scene-element/dist/scroll-scene-element.js" type="module"></script>
7878
<script type="module">
79-
const offset = 0.5;
79+
const offset = 0.75;
8080

8181
function getRandomIntInclusive(min, max) {
8282
min = Math.ceil(min);
@@ -88,6 +88,7 @@
8888

8989
scenes.forEach((scene) => {
9090
scene.style.padding = getRandomIntInclusive(200, 400) + 'px 0';
91+
scene.offset = offset;
9192
})
9293

9394
document.querySelector('.midpoint').style.top = (1 - offset) * 100 + '%';

src/scroll-scene-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function observeProgress(element: ScrollSceneElement): ProgressCommands {
8686
// ensure progress is never less than 0 or greater than 1
8787
const progress = Math.max(
8888
0,
89-
Math.min((window.innerHeight * offset - top) / (bottom - top), 1),
89+
Math.min((window.innerHeight * (1 - offset) - top) / (bottom - top), 1),
9090
);
9191

9292
element.dispatchEvent(

0 commit comments

Comments
 (0)