-
-
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 (set) #26
Comments
Hi Felix (@xiel), I'm currently investigating this feature and I'd like to discuss it further with you. This feature mainly raises one concern for me. I recently implemented But I imagine that setting Any thoughts regarding this? Kindly, |
To be honest I think both methods should support being set frequently (every frame) & hard. Calculating the snap point should not be a very expensive calculation when the layout & snap points stayed the same? |
Thanks for your input Felix (@xiel), Well yes, maybe it's not an expensive calculation. But there is another thing to consider. Setting this frequently (every frame) from let's say snap index 0 to 4 will trigger the
Another question is how we should solve this when Thanks in advance, |
|
Thanks for your input Felix (@xiel). I'll consider your thoughts and input when implementing this feature. I'm looking into this so I'll let you know when I have something. Best |
Hello Felix (@xiel), I'm excited to announce release v2.9.1 which comes with a new set of utilities to manipulate the current scroll progress. Please read the release description for further details 🎉. Just as an example, it's now possible for a carousel to imitate another carousels progress like so: carouselOne.on('select', () => {
const target = true
const carouselOneProgressTarget = carouselOne.scrollProgress(target) // boolean true gets the target scroll progress instead of current scroll progress
carouselTwo.scrollToProgress(carouselOneProgressTarget)
} I'd very much appreciate if you could confirm that it's working as expected. Cheers! |
Can you explain what is the difference between target and not target position in scrollProgress(true/false). Not very clear to me atm, when are the numbers different? Everything looks great, thanks so much! |
Thanks @xiel for the feedback. So the difference is: Location progress: Target progress: Is this explanation better? Let me know if this makes sense 🙂. Cheers! |
@davidjerleke Ah yes, totally makes sense! Thanks! What do you think would be the best way to update the scrollPos by px values now? For example, I know I want to move 20px from current position, how can I translate that to the percent I need for scrollBy(x). I would need to have 20 / scrollLength? Background |
Ah I see. I'm going to add the wheel scrolling feature to Embla as discussed in issue #47 as soon as possible. This will be an option and not mandatory. Will this help your case? Or am I misunderstanding you maybe? |
I'm basically offering you, to basically take over implementing issue #47 ;) |
I understand! That would be awesome @xiel 🙂. I've had this "crazy" idea for a while now, about exposing the Embla engine with all its internal utils like so: embla.dangerouslyGetEngine() But I'm afraid the lib will drown in issues if I do this 🙈. But maybe it's just enough to expose the internal |
For future extensibility exposing the full engine would surely be a bit more dangerous, but a good choice IMHO. I think it would be a great way to able to add functionality via plugins/wrappers which could be installed separately, so the main package stays small and tidy. |
Thanks for the feedback @xiel. Appreciate your thoughts and efforts 👍. Do you think I should add the engine exposure to the README? Because doing so might lead to a lot of issues about how to achieve this and that. Or do you want me to just do it and send you the info? |
I think everyone who wants to use the engine directly needs to dive a bit into the code anyway, so I don't think there is a need to add lot of documentation for it :) Happy to get it via mail or it could be a small section in CONTRIBUTING.md or another extra file? |
Thanks! I'll let you know when I have something. Cheers! |
Hi Felix (@xiel), I'm preparing for the release of Embla v.3, but this might take a week or so to finish, so I've decided to commit and push the api method that exposes the engine, and I've done so in this commit. So if you clone the repo you should be able to make use of: const engine = embla.dangerouslyGetEngine() ...now 🙂. For anyone building an extension package for Embla I'd be very happy to help out with how the engine works. So feel free to ask questions if you're building the scroll wheel package. With the engine exposed, you won't need // Grab engine
const engine = embla.dangerouslyGetEngine()
// When wheel starts scrolling you can do this
engine.scrollBody.useSpeed(80) // This attraction is so much that it will almost move instantly
engine.animation.start()
// Update target so attraction kicks in and moves the carousel towards its target
const pxToScrollBy = wheelDeltaInPx
const percentToScrollBy = engine.pxToPercent(pxToScrollBy) // Convert px to percent
engine.target.add(percentToScrollBy) Please take a closer look at Kindly |
@davidjerleke Perfect thanks! I'll let you know when I have something to show or questions ;) |
@davidjerleke amazing job with the library! Using it in several projects at the moment. Just wanted to check if the function |
@phmasek thanks. The CodeSandbox in this comment might help you achieve what you want. Yes, Please note that you need to change all calls to Best |
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.. |
Is there anyway to achieve this in the latest version of Embla? I'm looking to scroll one carousel, and have the relative scroll progress update another carousel.
|
Did you check this comment out? And this comment could also be helpful. Best, |
Hi David (@davidjerleke), I did, and they were helpful - I've got carousel A scrolling carousel B simultaneously. I'm having an issue scrolling carousel B to the relative amount of carousel A, as the carousels are different heights (scrolling on the Y axis). For example, when carousel A has slide index 2 aligned in the center, then carousel B should also have it's slide index 2 aligned to the center too. I also need to figure how to stop scrolling the carousels when they hit their boundarys. Any help would be greatly appreciated. Thanks, |
Oh yeah. Embla has changed to px instead of % since that example was created. That’s why you’re experiencing problems. I guess you could use the I’m very busy with the upcoming version 8 so unfortunately I won’t be able to help you soon. Best, |
👉 Feature Specification
As discussed in issue #21.
Special thanks
@xiel for this feature request.
The text was updated successfully, but these errors were encountered: