-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Scroll Progress (get) #21
Comments
Hey David, Would you also consider an API for setting of scroll progress at the same time? This could be used to sync Embla to external things (like scroll position in one-pagers or other kinds of user input). Cheers! |
Hi Felix (@xiel), Just want to confirm that I understand you correctly. At the time of writing we have a method called:
Is this what you had in mind? Best, |
I had a get/set interface in mind, so when you do not pass anything, you get the current value back. And if you pass something, this value will gets applied.
Sometimes relative change to the current position is more interesting. For that, a second convenience method could offer to update the position by a relative value (similar to window.scrollBy):
I think it makes sense to also allow setting and getting in px dimensions, this could be done either as a second parameter (px / %) or side-by-side as own methods?
Recarding the unit, I would also suggest to use 0..1 range for percentage (instead of 1..100), as it is more common in JS and easier to distinguish from px values. Sorry for all the requests. Happy to take this into a separate issue if it's to much here ;) |
Hello Felix (@xiel), That's surely a lot to take in 😄. But I always appreciate ideas so thank you for taking time to discuss this. So I think embla.scrollProgress()
// get scroll progress
// returns a number from 0 - 1 representing % scrolled of scrollable distance And I think I understand the idea for embla.scrollProgress(0.5)
// set scroll progress
// accepts a number from 0 - 1 representing % scrolled of scrollable distance embla.scrollBy(0.5)
// set scroll position relative to current
// accepts a number from 0 - 1 representing % to scroll based on current scroll position Methods like Regarding Best |
Hi David (@davidjerleke), A couple of months ago I forked this repository with a similar idea in mind. I wanted to create a carousel with parallax effect and changing background gradient but in order to do this I needed the scroll progress. I made a quick implementation to experiment with this a bit. Here's an example: https://codesandbox.io/embed/embla-carousel-scroll-event-czzbo |
Hey @davidjerleke, use cases for setting the scroll position manually:
I think it does not make sense to implement all these use cases within Embla itself, but I would love to see the API evolve and being able to implement them myself when needed. And a way to change the scroll position would definitely be needed for that. I agree that the developer might move the carousel to arbitrary positions, that should be a solvable challenge. Could the developer not just call I have not dived deep into the code, but don't you already map from px dimensions to % dimensions in your drag implementation? Otherwise providing the scroll length would also be sufficient, then the developer could map to percentage values himself. Best, |
Hello Han (@welteki), Very creative with the background color changing, I like it 😄. And thank you for this example, I think it's a great demonstration for other users browsing this issue. This feature will be implemented as soon as possible. Do you have any further ideas about this feature that you think could be valuable? Best, |
Hi @xiel, Thank you for taking time to explain 💪.
You're absolutely right about this. I've decided to split all feature requests in this discussion into separate issues. I think it will make it easier to follow each feature request and implement them separately, one by one. I hope this is ok with you. Please see ScrollBy #23. Best, |
Hi Felix (@xiel), About the method for setting scroll progress Thank you for your attention! |
Yes, I would expect it to be an instant setter by default. |
I'm happy to announce that the first part of this, the scroll progress getter has been released with version 2.5.0 🚀. Read more here or check this CodeSandbox out. Enjoy! |
👉 Conclusion / Feature Specification
The discussion in this issue has resulted in a decision to implement the following API method:
Example Usage
CodeSandbox
See example usage.
Special thanks
@xiel for discussing this and sharing your thoughts and ideas.
@welteki for the nice demonstration.
The text was updated successfully, but these errors were encountered: