question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll Progress (set)

See original GitHub issue

👉 Feature Specification

// set scroll progress
// accepts a number from 0 - 1 representing % scrolled of scrollable distance
// scroll to target is smooth

embla.scrollToProgress(0.5)

As discussed in issue #21.

Special thanks

@xiel for this feature request.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:21 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
phmasekcommented, Dec 20, 2021

Perfect, thank you! I created a callback function based on your CodeSandbox that could easily be used for connecting scroll.

const scrollToProgress = React.useCallback(
  (progress: number) => {
    if (!embla) return;

    const { limit, target, scrollProgress, scrollBody, scrollTo } = embla.internalEngine();
    const currentProgress = scrollProgress.get(target.get());
    const allowedProgress = Math.min(Math.max(progress, 0), 1);
    const progressToTarget = allowedProgress - currentProgress;
    const distance = progressToTarget * limit.length * -1;

    scrollBody.useBaseMass().useBaseSpeed();
    scrollTo.distance(distance, false);
  },
  [embla]
);

I know it’s suboptimal considering that the library moved towards a plugins paradigm. Hopefully I’ll get the time to contribute with a plugin. But until then the callback might be useful for someone…

1reaction
davidjerlekecommented, Dec 20, 2021

@phmasek thanks.

The CodeSandbox in this comment might help you achieve what you want.

Yes, scrollToProgress() was removed in v3. Release details here.

Please note that you need to change all calls to embla.dangerouslyGetEngine() to embla.internalEngine() if you’re using v6 and up. Read more about all breaking changes in the release details.

Best David

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll progress indicator | Webflow University
A scroll progress indicator helps visitors track where they are on a page. In this lesson: Design the progress bar · Set up...
Read more >
How to Add a Page Scroll Progress Bar at the Top of Your ...
How to Add a Page Scroll Progress Bar at the Top of Your Startup Webpage. Contents. Adding the Progress Indicator to the Page;...
Read more >
Scroll Progress Element - ThemeFusion | Avada Website ...
The Scroll Progress Element is new in Avada 7.3 and is the perfect Element to actively show your users how far they are...
Read more >
Create A Scroll Indicator Progress Bar In React & Tailwind CSS
We will create scroll indicator progress bar, I see this indicator progress bar on some blogs, which helps gauge how much of the...
Read more >
How To Create a Scroll Indicator - W3Schools
We have created a "progress bar" to show how far a page has been scrolled. It also works when you scroll back up....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found