悬停鼠标时JavaFx旋转按钮
JavaFx rotate button when hover mouse
当我将鼠标放在按钮上时(悬停),有什么方法可以旋转按钮吗?
通过使用纯 JavaFx ,或通过使用 CSS 样式?
如果没有,我会在鼠标悬停时寻找任何简单的动画
只需创建一个 RotateTransition
并使用鼠标处理程序启动和暂停它:
Button button = ... ;
RotateTransition rotation = new RotateTransition(Duration.seconds(0.5), button);
rotation.setCycleCount(Animation.INDEFINITE);
rotation.setByAngle(360);
button.setOnMouseEntered(e -> rotation.play());
button.setOnMouseExited(e -> rotation.pause());
当我将鼠标放在按钮上时(悬停),有什么方法可以旋转按钮吗? 通过使用纯 JavaFx ,或通过使用 CSS 样式? 如果没有,我会在鼠标悬停时寻找任何简单的动画
只需创建一个 RotateTransition
并使用鼠标处理程序启动和暂停它:
Button button = ... ;
RotateTransition rotation = new RotateTransition(Duration.seconds(0.5), button);
rotation.setCycleCount(Animation.INDEFINITE);
rotation.setByAngle(360);
button.setOnMouseEntered(e -> rotation.play());
button.setOnMouseExited(e -> rotation.pause());