Previously, we've improved the JavaFX animation story by making
backgrounds and borders interpolatable, and adding timeline-driven
CSS-based transitions that automatically run when the state of a node
changes.
What's still missing is scroll transitions. A scroll transition is not
triggered by a state change, but by a scroll gesture performed by the
user. It is defined by a new property on VirtualFlow-based controls
(ListView, etc.) and on ScrollPane:
/**
* Specifies the transition used to animate discrete
* mouse-wheel scrolling.
* <p>
* The transition is applied when scrolling occurs in
* discrete wheel steps. It is not applied to fine-grained
* precision scrolling by a touchpad or a high-resolution
* mouse wheel.
*
* @defaultValue {@code null}
* @since 28
*/
private ObjectProperty<ScrollTransition> scrollTransition;
Here's how ScrollTransition is defined:
public sealed interface ScrollTransition
permits ScrollTransition.Spring,
ScrollTransition.ExponentialDecay {
record Spring(double naturalFrequency,
double dampingRatio)
implements ScrollTransition { ... }
record ExponentialDecay(Duration halfLife)
implements ScrollTransition { ... }
}
When a scroll event is encountered that exceeds a continuous-scrolling
threshold, the viewport is animated to its new position as defined by
the ScrollTransition.
Here's how it looks like in action:
https://github.com/user-attachments/assets/edf65b66-3ec3-4495-9c70-9154c586515e
It is probably a good idea to allow scroll transitions be
CSS-styleable. However, this is not a standard CSS property, so we'd
need to invent a JavaFX-specific grammar.
If there is interest in this feature, I can prepare a PR with the
implementation.