Skip to content

Commit 379bd0d

Browse files
committed
Fix various issues with automatically set inpoints and outpoints depending on combinations of mode and autoStart settings
1 parent 36a240b commit 379bd0d

File tree

10 files changed

+61
-51
lines changed

10 files changed

+61
-51
lines changed

dist/esm/pushin.js

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

dist/esm/pushin.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/umd/pushin.js

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

dist/umd/pushin.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/umd/pushin.min.js

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

src/pushInLayer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,19 @@ export class PushInLayer extends PushInBase {
157157
* Get all inpoints for the layer.
158158
*/
159159
private getInpoints(element: HTMLElement, index: number): number[] {
160-
let inpoints = [this.scene.getTop()];
160+
const { scene } = this;
161+
let inpoints = [0];
161162
if (element.dataset[PUSH_IN_FROM_DATA_ATTRIBUTE]) {
162163
inpoints = element.dataset[PUSH_IN_FROM_DATA_ATTRIBUTE]!.split(',').map(
163164
inpoint => parseInt(inpoint.trim(), 10)
164165
);
165166
} else if (this.settings?.inpoints) {
166167
inpoints = this.settings.inpoints;
167-
} else if (index === 0 || this.scene.getMode() === 'continuous') {
168+
} else if (this.isFirst || scene.getMode() === 'continuous') {
168169
inpoints = this.scene.getInpoints();
169170
} else if (index > 0) {
170171
// Set default for middle layers if none provided
171-
const { outpoint } = this.scene.layers[index - 1].params;
172+
const { outpoint } = scene.layers[index - 1].params;
172173
inpoints = [outpoint - this.getOverlap()];
173174
}
174175

src/pushInScene.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ export class PushInScene extends PushInBase {
193193
* @returns {number}
194194
*/
195195
getTop(): number {
196-
let { top } = this.container!.getBoundingClientRect();
197-
if (this.pushin.target!.container) {
198-
top -= this.pushin.target!.container.getBoundingClientRect().top;
199-
}
200-
return top;
196+
return this.container!.getBoundingClientRect().top;
201197
}
202198

203199
/**
@@ -207,11 +203,7 @@ export class PushInScene extends PushInBase {
207203
* @returns {number[]}
208204
*/
209205
getInpoints(): number[] {
210-
let inpoints = <number[]>[this.getTop()];
211-
const containerTop =
212-
this.container!.getBoundingClientRect().top +
213-
document.documentElement.scrollTop;
214-
206+
let inpoints = [0];
215207
if (this.container!.dataset[PUSH_IN_FROM_DATA_ATTRIBUTE]) {
216208
const pushInFrom = <string>(
217209
this.container!.dataset[PUSH_IN_FROM_DATA_ATTRIBUTE]
@@ -220,9 +212,9 @@ export class PushInScene extends PushInBase {
220212
} else if (this.settings?.inpoints && this.settings?.inpoints.length > 0) {
221213
inpoints = this.settings.inpoints;
222214
} else if (this.settings?.autoStart === 'screen-bottom') {
223-
inpoints = [containerTop - window.innerHeight];
215+
inpoints = [this.getTop() - window.innerHeight];
224216
} else if (this.settings?.autoStart === 'screen-top') {
225-
inpoints = [containerTop];
217+
inpoints = [this.getTop()];
226218
}
227219

228220
return inpoints;

src/pushin.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,22 @@ export class PushIn extends PushInBase {
251251
const calculated = maxOutpoint + targetHeight;
252252

253253
// Get the existing container height.
254-
const height = parseFloat(
254+
const containerHeight = parseFloat(
255255
getComputedStyle(this.container).height.replace('px', '')
256256
);
257257

258+
let height = Math.max(containerHeight, calculated);
259+
260+
if (
261+
calculated < window.innerHeight &&
262+
this.mode === 'continuous' &&
263+
this.scene.settings.autoStart === 'screen-top'
264+
) {
265+
height += window.innerHeight;
266+
}
267+
258268
// Use the largest value between existing container height, largest outpoint or calculated height.
259-
this.container.style.height = `${Math.max(height, calculated)}px`;
269+
this.container.style.height = `${height}px`;
260270
}
261271

262272
loadStyles(): void {

stories/AutoStart.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ ScreenTopContinuous.args = {
4646
settings: {
4747
autoStart: 'screen-top',
4848
mode: 'continuous',
49+
debug: true,
4950
},
5051
};

stories/Modes.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ ContinuousWithTransitions.args = {
4343
},
4444
{
4545
transitions: true,
46+
transitionStart: 300,
47+
transitionEnd: 300,
4648
},
4749
{
4850
transitions: true,
49-
inpoints: [100],
51+
inpoints: [200],
52+
transitionStart: 300,
53+
transitionEnd: 300,
5054
},
5155
],
5256
},

0 commit comments

Comments
 (0)