Skip to content

Commit

Permalink
Fix docs, export setTargetTimePercent in vue and svelte (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaoster authored Mar 22, 2024
1 parent 5750cda commit 9412665
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ Add html code to your html component:

Additionally, to set currentTime manually:

***setCurrentTimePercent*** (`percentage: number`, `options: Options`): Pass a progress in between of 0 and 1 that specifies the percentage position of the video. Optionally, to customise experience of separate `setCurrentTimePercent` calls you can utilise options:
***setTargetTimePercent*** (`percentage: number`, `options: Options`): Pass a progress in between of 0 and 1 that specifies the percentage position of the video. Optionally, to customise experience of separate `setTargetTimePercent` calls you can utilize options:
- `transitionSpeed`: `number`
- `easing`: `(progress: number) => number`

Example: `setCurrentTimePercent(0.5, { transitionSpeed: 12, easing: d3.easeLinear })`
Example: `setTargetTimePercent(0.5, { transitionSpeed: 12, easing: d3.easeLinear })`

## Technical Details and Cross Browser Differences
To make this library perform optimally in all browsers, three different approaches are taken to animating the video.
Expand Down
4 changes: 2 additions & 2 deletions src/ScrollyVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ScrollyVideo {
if (this.debug) console.info('ScrollyVideo scrolled to', scrollPercent);

// Set the target time percent
this.setTargetTimePercent(scrollPercent, jump);
this.setTargetTimePercent(scrollPercent, { jump });
};

// Add our event listeners for handling changes to the window or scroll
Expand All @@ -145,7 +145,7 @@ class ScrollyVideo {
} else {
this.video.addEventListener(
'loadedmetadata',
() => this.setTargetTimePercent(0, true),
() => this.setTargetTimePercent(0, { jump: true }),
{ once: true },
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ScrollyVideo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const ScrollyVideoComponent = forwardRef(function ScrollyVideoComponent(
useImperativeHandle(
ref,
() => ({
setVideoPercentage: scrollyVideoRef.current
setTargetTimePercent: scrollyVideoRef.current
? scrollyVideoRef.current.setTargetTimePercent.bind(instance)
: () => {},
}),
Expand Down
7 changes: 6 additions & 1 deletion src/ScrollyVideo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Store the props so we know when things change
let lastPropsString = '';
$: {
if (scrollyVideoContainer) {
// separate out the videoPercentage prop
Expand All @@ -32,6 +32,11 @@
}
}
// export setTargetTimePercent for use in implementations
export function setTargetTimePercent(...args) {
scrollyVideo.setTargetTimePercent(...args);
}
// Cleanup the component on destroy
onDestroy(() => {
if (scrollyVideo && scrollyVideo.destroy) scrollyVideo.destroy();
Expand Down
3 changes: 3 additions & 0 deletions src/ScrollyVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default {
...props,
});
},
setTargetTimePercent(...args) {
if (this.scrollyVideo) this.scrollyVideo.setTargetTimePercent(...args);
}
},
watch: {
$attrs: {
Expand Down

0 comments on commit 9412665

Please sign in to comment.