Skip to content

Commit 70d35df

Browse files
committed
fix bug with multiple unwrapGrid calls
1 parent ecb7942 commit 70d35df

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

demo/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@ grid.addEventListener('click', ev => {
3333
}
3434
});
3535

36+
const { uwg } = wrapGrid(grid, {
37+
easing: 'backOut',
38+
onStart: els => console.log('onstart', els),
39+
onEnd: els => console.log('onend', els),
40+
});
41+
42+
uwg();
43+
console.log('unwrapped');
44+
3645
const { unwrapGrid } = wrapGrid(grid, {
3746
easing: 'backOut',
3847
onStart: els => console.log('onstart', els),
3948
onEnd: els => console.log('onend', els),
40-
containerScroll: true,
4149
});
4250

4351
document
@@ -180,5 +188,4 @@ scrollTest.addEventListener('click', () => {
180188
});
181189
wrapGrid(scrollTest, {
182190
duration: 2000,
183-
containerScroll: true,
184191
});

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { WrapGridArguments } from './types';
2-
export declare const wrapGrid: (container: HTMLElement, { duration, stagger, easing, onStart, onEnd, containerScroll, }?: WrapGridArguments) => {
2+
export declare const wrapGrid: (container: HTMLElement, { duration, stagger, easing, onStart, onEnd, }?: WrapGridArguments) => {
33
unwrapGrid: () => void;
44
forceGridAnimation: () => void;
55
};

dist/main.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ export interface WrapGridArguments {
4444
easing?: keyof PopmotionEasing;
4545
onStart?: (animatedChildren: HTMLElement[]) => void;
4646
onEnd?: (animatedChildren: HTMLElement[]) => void;
47-
containerScroll?: boolean;
4847
}

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ export const wrapGrid = (
128128
if (!el.dataset[DATASET_KEY]) {
129129
const newId = `${Math.random()}`;
130130
el.dataset[DATASET_KEY] = newId;
131-
cachedPositionData[newId] = {} as ItemPosition;
132131
}
133132
const animateGridId = el.dataset[DATASET_KEY] as string;
133+
134+
if (!cachedPositionData[animateGridId]) {
135+
cachedPositionData[animateGridId] = {} as ItemPosition;
136+
}
137+
134138
const rect = getGridAwareBoundingClientRect(gridBoundingClientRect, el);
135139
cachedPositionData[animateGridId].rect = rect;
136140
cachedPositionData[

0 commit comments

Comments
 (0)