I need to implement the morphing floating button functionality in my application.
I've created the needed CSS classes, and now I need to listen to element scroll to be able to apply some styles.
I've managed to implement this as follow and it works perfectly:
fromEvent(scrollableElement, 'scroll')
.pipe(untilDestroyed(this), debounceTime(100))
.subscribe(() => {
const currentScrollPos = scrollableElement.scrollTop;
buttonTextElement.classList.toggle('d-none', prevScrollPos < currentScrollPos);
prevScrollPos = currentScrollPos;
});
Now I'm trying to improve this from a performance perspective and I was thinking about the following scenario:
- Listen to scroll
- Take only first emit of scroll down and skip the rest until scroll up
- Take only first emit of scroll up and skip the rest until scroll down
- Repeat
Is there a possibility to do this with RxJs operators?