Skip to content

Commit f6e8ac0

Browse files
committed
Make sure setting the offset dynamically correctly removes the default observer
1 parent 96423b9 commit f6e8ac0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/scroll-scene-element.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const DEFAULT_OFFSET = 0.5;
12
const offsetObservers = new Map<number, IntersectionObserver>();
23
type ProgressCommands = { on: () => void; off: () => void };
34
const progressListeners = new WeakMap<ScrollSceneElement, ProgressCommands>();
@@ -122,9 +123,9 @@ class ScrollSceneElement extends HTMLElement {
122123
disconnectFromObserver(this, this.offset);
123124
}
124125

125-
attributeChangedCallback(attribute: string, previousValue: string) {
126+
attributeChangedCallback(attribute: string, oldValue: string) {
126127
if (attribute === 'offset') {
127-
const previousOffset = Number.parseFloat(previousValue);
128+
const previousOffset = Number.parseFloat(oldValue) || DEFAULT_OFFSET;
128129

129130
if (previousOffset !== this.offset) {
130131
disconnectFromObserver(this, previousOffset);
@@ -138,7 +139,7 @@ class ScrollSceneElement extends HTMLElement {
138139
}
139140

140141
get offset() {
141-
return Number.parseFloat(this.getAttribute('offset')) || 0.5;
142+
return Number.parseFloat(this.getAttribute('offset')) || DEFAULT_OFFSET;
142143
}
143144

144145
set offset(value: number) {

0 commit comments

Comments
 (0)