How to add CSS AnimationEnd event handler to GWT widget?

后端 未结 3 866
情话喂你
情话喂你 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:41

    Based on Darthenius' answer and Clay Lenhart's Blog, I finally settled for this solution:

    private native void registerAnimationEndHandler(final Element pElement,
        final CbAnimationEndHandlerIF pHandler)
    /*-{
        var callback = function(){
           pHandler.@fully.qualified.CbAnimationEndHandlerIF::onAnimationEnd()();
        }
        if (navigator.userAgent.indexOf('MSIE') < 0) {  // no MSIE support
           pElement.addEventListener("webkitAnimationEnd", callback, false); // Webkit
           pElement.addEventListener("animationend", callback, false); // Mozilla
        }
    }-*/;
    

    The CbAnimationEndHandlerIF is a simple custom EventHandler interface:

    public interface CbAnimationEndHandlerIF extends EventHandler
    {
        void onAnimationEnd();
    }
    

    Works like a charm! Thanks Darthenius!

    If anyone can spot a weakness in this, of course I'd be happy to know.

提交回复
热议问题