How to add CSS AnimationEnd event handler to GWT widget?

后端 未结 3 865
情话喂你
情话喂你 2021-01-13 02:19

I would like my GWT widget to be notified when its CSS animation is over.

In plain HTML/Javascript this is easily done by registering an event handler like so:

3条回答
  •  星月不相逢
    2021-01-13 02:53

    You can always write some of the native (JavaScript) code yourself:

    public class CssAnimation {
      public static native void registerCssCallback(
          Element elem, AsyncCallback callback) /*-{
        elem.addEventListener("webkitAnimationEnd", function() {
          $entry(@CssAnimation::cssCallback(Lcom/google/gwt/user/client/rpc/AsyncCallback;)(callback));
        }, false);
      }-*/;
    
    
      protected static void cssCallback(AsyncCallback callback) {
        callback.onSuccess(null);
      }
    }
    

    I haven't tried the code above. Let me know if it works as expected.


    You can use GWT's Animation class to achieve the same effect. For example,

      new com.google.gwt.animation.client.Animation() {
        final com.google.gwt.dom.client.Style es = widget.getElement().getStyle();
    
        @Override
        protected void onUpdate(double progress) {
          setOpacity(1 - interpolate(progress));
        }
    
        private void setOpacity(double opacity) {
          es.setProperty("opacity", Double.toString(opacity));
          es.setProperty("filter", "alpha(opacity=" + 100 * opacity + ")");
        }
    
        @Override
        protected void onComplete() {
          /* ... run some code when animation completes ... */
        }
      }.run(2000, 5000);
    

提交回复
热议问题