简体   繁体   English

如何将css-keyframes添加到vaadin组件?

[英]How to add css-keyframes to vaadin components?

I'd like to add a keyframe-animation to a vaadin Label component: the background should make a colored transition from red to yellow . 我想在vaadin Label组件中添加一个关键帧动画:背景应该是从redyellow的彩色过渡。

But the bg color does not change in any way. 但是bg颜色不会以任何方式改变。 Am I missing anything? 我错过了什么吗?

private Label label = new Label("background red fading");
lable.setCss("red");

css: CSS:

.v-label-red {
    @include red;
}

keyframe: 关键帧:

@-webkit-keyframes red {
    from {background: red;}
    to {background: yellow;}
}
@keyframes red {
    from {background: red;}
    to {background: yellow;}
}

be sure to have the @keyframes out of your main @mixin of the theme. 一定@mixin主题的主要@mixin中取出@mixin Next your .v-label-red needs the background set (most likely to the same as the to in the keyframes and also it needs some time to handle it (now it basically goes from white -> red -> yellow -> white in no time. here is an example, that should bring you on the right track: 接下来你的.v-label-red需要背景设置(最有可能与关键帧中的to相同,也需要一些时间来处理它(现在它基本上是从白色 - >红色 - >黄色 - >白色没有时间。这是一个例子,应该带你走上正轨:

CSS CSS

@import "../reindeer/reindeer.scss";

@keyframes keyframe1 {
    from {background: red;}
    to {background: yellow;}
}
@keyframes keyframe2 {
  from {background: yellow;}
  to {background: red;}
}

@mixin app {
  @include reindeer;

  .keyframe1 {
    background: yellow;
    -webkit-animation: keyframe1 1s linear;
    -moz-animation: keyframe1 1s linear;
    -ms-animation: keyframe1 1s linear;
    animation: keyframe1 1s linear;
  }

  .keyframe2 {
    background: red;
    -webkit-animation: keyframe2 1s linear;
    -moz-animation: keyframe2 1s linear;
    -ms-animation: keyframe2 1s linear;
    animation: keyframe2 1s linear;
  }

}

Vaadin UI code (groovy) Vaadin UI代码(groovy)

@VaadinUI
@Theme('app')
@CompileStatic
class AppUI extends UI {

    final static String K1 = 'keyframe1'
    final static String K2 = 'keyframe2'

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final layout = new VerticalLayout()
        layout.setSpacing(true)
        layout.setMargin(true)
        final headline = new Label('Hello World')
        headline.addStyleName(K1)
        final button = new Button("toggle", {
            if (headline.styleName.contains(K1)) {
                headline.addStyleName(K2)
                headline.removeStyleName(K1)
            } else {
                headline.addStyleName(K1)
                headline.removeStyleName(K2)
            }
        } as Button.ClickListener)
        layout.addComponents(headline, button)
        setContent(layout)
    }

}

This code will fade the label on loading and will fade between the two states on button clicks. 此代码将在加载时淡化标签,并在按钮单击时在两种状态之间淡入淡出。

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

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