0

有没有办法以编程方式定义和启动 CSS 动画?我想将 div 从一个绝对位置移动到另一个位置。就像是:

FlowPanel fp = new FlowPanel();
fp.getElement().getStyle().setPosition(Position.ABSOLUTE);
fp.getElement().getStyle().setLeft(50, Style.Unit.PX);
fp.getElement().getStyle().setTop(50, Style.Unit.PX);

...

// something like:
fp.setAnimation("top: 300px");

我看到我们可以在我们的css文件中定义一个css动画,改变div的样式名称会触发动画。但我不知道我们是否可以通过编程方式修改 css 中定义的动画。例如:

// css file
.testAnimation {
  top: 500px;
  transition-property: top;
  transition-duration: 1s;
}

...

// But we can't modify the "top" attribute here depending on runtime needs?:
fp.setStyleName("testAnimation"); // I may want "top" to be some other value here.

谢谢

4

2 回答 2

0

您可以使用getElement().getStyle().setProperty( property, value )来设置任何 css 属性。但这不是正确的做法。建议的方法是通过 css 来做。

链接可能对您有所帮助

于 2013-01-10T03:21:40.770 回答
0

你有几种方法

1) GWT 动画 - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwAnimation

2) Jquery 方法 - 通过 GWTQuery - https://groups.google.com/forum/?fromgroups=#!topic/google-web-toolkit/6kOSm0HBP4A

3) GWT 中的 JSNI -如何将 CSS AnimationEnd 事件处理程序添加到 GWT 小部件?

于 2013-01-10T03:34:23.907 回答