Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t throw on invalid ranges, but ignore them #289

Open
bramus opened this issue Oct 17, 2024 · 1 comment
Open

Don’t throw on invalid ranges, but ignore them #289

bramus opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bramus
Copy link
Collaborator

bramus commented Oct 17, 2024

Follow-up on #285, which turned out to be an issue with the range being used.

Glad you got your Firefox problem (which could have used its own issue in this repo) sorted. The culprit is that you were using the wrong offsets: the cover, contain, entry, exit, etc. ranges can only be used with ViewTimeline, not ScrollTimeline.

There is an argument to be made that the polyfill should mimic the native API here so that it ignores the incorrect offsets instead of throwing an Error

The OP tried to use a ViewTimeline-range with a ScrollTimeline, and it resulted in an error being thrown. The native implementation just silently ignores the invalid range.

@bramus
Copy link
Collaborator Author

bramus commented Oct 17, 2024

The following throws with the polyfill, but not in Chrome:

var videoElement = document.querySelector('[data-section-id="66d339fcaa91932c1202ad7e"] video');

var scrollTimeline2 = new ScrollTimeline({
    source: document.documentElement,
    axis: "block",
    orientation: 'block'
});

videoElement.animate(
    { transform: ["translateY(0)", "translateY(-33vh)"]},
    {
        duration: 1000, 
        fill: 'both',
        timeline: scrollTimeline2,
        rangeStart: {
          rangeName: 'cover',
          offset: CSS.percent('70')
        },
	rangeEnd: {
          rangeName: 'cover',
          offset: CSS.percent('100')
        }
    }
);

The author actually intended this:

var videoElement = document.querySelector('[data-section-id="66d339fcaa91932c1202ad7e"] video');

var scrollTimeline2 = new ScrollTimeline({
          source: document.documentElement,
         axis: "block",
        orientation: 'block'
});

videoElement.animate(
    { transform: ["translateY(0)", "translateY(-33vh)"]},
    {
        duration: 1000, 
        fill: 'both',
        timeline: scrollTimeline2,
        rangeStart: new CSSUnitValue(70, 'percent'),
        rangeEnd: new CSSUnitValue(100, 'percent')
    }
);

@bramus bramus added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant