简体   繁体   English

GWT-将元素添加到页面后的CSS动画

[英]GWT - CSS animation after adding element to the page

If the button is clicked, I want to add a Label to page and fade it in via an CSS animation. 如果单击该按钮,我想在页面上添加标签,然后通过CSS动画淡入标签。 I thougt, I could just create and add the label with the CSS class "hidden" attached, which has the opacity = 0 and after that remove the class and CSS will do the rest. 我想,我可以创建并添加带有CSS类“ hidden”的标签,该标签的不透明度= 0,然后删除该类,其余的工作由CSS完成。 But i was wrong. 但是我错了。 GWT seems to execute the code in the onClick() in some kind of bulk mode -> The label gets added already without the "hidden" class. GWT似乎以某种批量模式执行onClick()中的代码->标签已被添加而没有“ hidden”类。 How can i prevent or do it that better? 我该如何预防或做得更好? If I add/remove the "hidden" class manually in the browser, the animation works finde. 如果我在浏览器中手动添加/删除“隐藏”类,则动画将自动查找。

The java code looks like this: Java代码如下所示:

Button submitButton = new Button("send");

submitButton.addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {

        Label l = new Label("test");
        l.addStyleName("hidden");
        RootPanel.get().add(l);

        l.removeStyleName("hidden");

    }
});

RootPanel.get().add(submitButton);

Das CSS sieht folgendermaßen aus: Das CSS siehtfolgendermaßenaus:

.gwt-Label{
    transition-property: opacity;
    transition-duration: 1s; 
}
.hidden{
    opacity:0;
}

Probably you have to add some delay function before remove hidden class. 可能必须在删除隐藏类之前添加一些延迟函数。

Here you have example (in JS but it's only to show): 这里有示例(在JS中,但仅用于显示):

http://jsfiddle.net/matku/PXnPZ/ http://jsfiddle.net/matku/PXnPZ/

$(".myElement").delay(50).queue( function(){
       $(this).removeClass("hidden");
});    

And another way I found on google: 我在Google上找到的另一种方式:

http://map-notes.blogspot.com/2012/11/fade-animation.html http://map-notes.blogspot.com/2012/11/fade-animation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM