Created
August 25, 2011 13:37
-
-
Save christiangoudreau/1170679 to your computer and use it in GitHub Desktop.
Gwt-Query fade animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Integer fadeDelay = 250; | |
private Boolean blockFade = false; | |
private String lastDesc = ""; | |
/** | |
* {@link Function} that insure that we wait until every fade animation is | |
* finished before unblocking upcoming fade animation. | |
*/ | |
private Function fadeFunction = new Function() { | |
@Override | |
public void f(Element e) { | |
blockFade = false; | |
} | |
}; | |
@Override | |
public void fadeDescription(SafeHtml desc) { | |
// Make sure that fading effect isn't blocked. | |
if (!blockFade && !lastDesc.equals(desc.toString())) { | |
lastDesc = desc.toString(); | |
if (fadeBlockTwo.isVisible() && !fadeBlockOne.isVisible()) { | |
switchFade(fadeBlockOne, fadeBlockTwo.getElement(), desc); | |
} else if (!fadeBlockTwo.isVisible()) { | |
switchFade(fadeBlockTwo, fadeBlockOne.getElement(), desc); | |
} | |
} | |
} | |
private void switchFade(HTML fadeBlock, Element element, SafeHtml desc) { | |
fadeBlock.setHTML(desc); | |
if (fadeBlock.isAttached()) { | |
blockFade = true; | |
$(fadeBlock).fadeIn(fadeDelay, fadeFunction); | |
$(element).fadeOut(fadeDelay, fadeFunction); | |
} else { | |
fadeBlockOne.setVisible(false); | |
fadeBlockTwo.setVisible(false); | |
fadeBlock.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment