GWT animation end value not respected

I have a FlowPanel which I am trying to animate back and forth like iphone nav. (See this article for my initial question on how to do this)

So, I have a β€œwork” with the code below. I say that I work in quotation marks because I find that my last position of my scroller is inaccurate and always changes when scrolling.

GWT.log always indicates the actual values ​​that I am looking for, for example with the call to scrollTo below, my GWT.log says:

ScrollStart: 0 scrollStop: -246

But when I really analyze an element in firebug, its css, the left position is never exactly -246px. Sometimes it turns off by 10 pixels, so my panel just stopped scrolling before it ended.

The worst part is that this navigator animates back and forth, so subsequent clicks can really drop it, and I need perfect pixel positioning, otherwise everything will look.

I don’t even know where to start debugging this, besides what I have already done. Any advice is appreciated.

EDIT: Additional Registration Information:
Writing to onUpdate shows this:

Updating: progress: 0.09319577524960648 position: -22.926160711403195
Updating: progress: 0.1328387452821571 position: -32.67833133941065
Updating: progress: 0.609071620698271 position: -149.83161869177468
Updating: progress: 0.7269952498697734 position: -178.84083146796425
Updating: progress: 0.9852532367342712 position: -242.37229623663072
AnimationComplete: final scrollStart/scrollStop: 0/-246

Why does it end at 0.98% ???

Code for invoking animation

scroller = new Scroller();
scroller.scrollTo(-246,400);

Animation code

public class Scroller extends Animation {

    private FlowPanel scroller;
    private final Element e;

    public Scroller(){
        scroller = new FlowPanel();
        e = scroller.getElement();
    }

    public void scrollTo(int position, int milliseconds) {

        scrollStart = e.getOffsetLeft();
        scrollStop = position;

        GWT.log("ScrollStart: " + scrollStart + " scrollStop: " + scrollStop);
        run(milliseconds);
    }

    @Override
    protected void onUpdate(double progress) {
        double position = scrollStart + (progress * (scrollStop - scrollStart));
        e.getStyle().setLeft(position, Style.Unit.PX);
    }
}
+5
source share
1 answer

onCompletecalled when the animation finishes (and onStartcalled before it starts), so override this if you want to perform the action when the animation is 100% complete:

public class Scroller extends Animation {
      ...

      @Override
      protected void onComplete() {
        e.getStyle().setLeft(scrollStop, Style.Unit.PX);
      }
}

brad, , onComplete - , . Javadoc Animation.onUpdate:

, . 0.0 1.0 ( () ). onStart() onComplete(), .

, , , onUpdate , , - a > 0, < 1.

+7

All Articles