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

fix initial jump #108

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/ScrollyVideoDemo.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import ScrollyVideo from '../src/ScrollyVideo.svelte';

const cards = [
'This kind of scrolling video is common in visual journalism, marketing materials, or other scrollytelling applications.',
'This library provides a way to easily create these kinds of scrolling video experiences, without fussing with special video encoding formats.',
Expand Down
6 changes: 6 additions & 0 deletions src/ScrollyVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class ScrollyVideo {
this.video.pause();
this.video.load();

// Start the video percentage at 0
this.videoPercentage = 0;

// Adds the video to the container
this.container.appendChild(this.video);

Expand Down Expand Up @@ -197,6 +200,9 @@ class ScrollyVideo {
* - easing: (progress: number) => number - A function that defines the easing curve for the transition. It takes the progress ratio (a number between 0 and 1) as an argument and returns the eased value, affecting the playback speed during the transition.
*/
setVideoPercentage(percentage, options = {}) {
// Early termination if the video percentage is already at the percentage that is intended.
if (this.videoPercentage === percentage) return;

if (this.transitioningRaf) {
// eslint-disable-next-line no-undef
window.cancelAnimationFrame(this.transitioningRaf);
Expand Down