简单的GWT动画

时间:2010-04-14 16:22:10

标签: gwt smartgwt gwt-ext gwt-animation

我已经开始查看一些external GWT个动画库了,但是对于我想要的东西来说,它们似乎都有些过分。

我正在尝试在GWT中模仿JQuery Tools scrollabel插件以进行滚动导航(想想iphone)。用户点击一个项目,页面滚动到该项目的子面板,该面板也可能有可以点击的子项。

我需要做的就是在一段固定的时间内向前和向后滑动div,x个像素

我在GWT编写动画时发现的唯一真实tutorial是2岁,看起来有点冗长,(管理个别帧等......)

是否没有简单的解决方案可以轻松地将div从一个位置移动到另一个位置而不需要额外的所有内容?

原谅我,但我来自简单易用的jQuery编码。

2 个答案:

答案 0 :(得分:4)

GWT 2内置的动画类非常好。您需要做的就是扩展类,实现onUpdate(),然后调用run()来启动动画。我没有使用scrollTop属性,所以我无法保证这将正常工作,但它应该给你基本的想法:

public class ScrollAnimation extends Animation {
    private final Element e;
    private int scrollStart;
    private int scrollStop;

    public ScrollAnimation(Element e) {
        this.e = e;
    }

    public scrollTo(int position, int milliseconds) {
        scrollStart = e.getPropertyInt("scrollTop");
        scrollStop = position;
        run(milliseconds);
    }

    @Override
    protected void onUpdate(double progress) {
        int position = scrollStart + (int)(progress * (scrollStop - scrollStart));
        e.setPropertyInt("scrollTop", position);
    }
}

答案 1 :(得分:0)

出于我的目的,我只想动画一个面板移动。事实证明这是内置在LayoutPanel中的,所以我根本不需要触摸Animation类。

http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html#Animation