GWT Animation final value is not respected
Posted
by brad
on Stack Overflow
See other posts from Stack Overflow
or by brad
Published on 2010-04-19T16:22:31Z
Indexed on
2010/04/19
16:23 UTC
Read the original article
Hit count: 311
gwt
|gwt-animation
I have a FlowPanel that I'm trying to animate back and forth like an iphone nav. (See this post for my original question on how to do this)
So I have it "working" with the code shown below. I say working in quotes because I'm finding that my final position of my scroller is not precise and always changes when scrolling.
The GWT.log always says the actual values I'm looking for, so for instance with the call below to scrollTo, my GWT.log says:
ScrollStart: 0 scrollStop: -246
But when I actually analyze the element in fireBug, its css, left position is never exactly -246px. Sometimes it's off by as much as 10px so my panel has just stopped scrolling before being finished.
The worst part is that this nav animates back and forth, so subsequent clicks can really throw it off, and I need pixel perfect positioning otherwise the whole things looks off.
I don't even know where to start with debugging this other than what I've already done. Any tips are appreciated.
Code to call 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);
}
}
© Stack Overflow or respective owner