What is the best way to incorporate CSS keyframes into Vaadin elements?

I'm trying to create a keyframe animation for a vaadin Label component where the background color transitions from red to yellow.

However, I am facing an issue where the background color does not change at all. Is there something that I have overlooked?

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

CSS:

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

Keyframe Animation:

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

Answer №1

Ensure that the @keyframes are not within your main @mixin of the theme. Additionally, your .v-label-red should have the background set (likely to the same as the to in the keyframes) and it needs some time to transition smoothly. Currently, it quickly shifts from white to red to yellow to white. Here is an example to guide you:

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)

@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 piece of code will create a fading effect on the label when loading and smoothly transition between two states upon button clicks.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble resolving "Iterator" as a type for <WebElement> in Selenium WebDriver

Issue Overview: I am currently using Selenium Webdriver to test a list of elements in a list box. However, when running the code provided below, I encounter an error. Testing Environment: Browser: Mozilla Firefox IDE: Eclipse Indigo Web driver: Selenium ...

Unusual div image alignment when dimensions are dynamically adjusted with Javascript animations

I have created a basic webpage using JavaScript that aims to scale an element from the center of the page over time when clicked. It is functioning properly for the SVG element I tested it with. However, when I use an image, it initially appears outside o ...

Scrollable carousel images with responsive design in bootstrap on mobile devices

While working with a responsive Bootstrap carousel, I've encountered an issue where there is a 'scroll' on mobile devices. Can anyone provide some helpful suggestions on how to resolve this? You can view the carousel in question at this lin ...

Tips on utilizing Media Player on Android devices

I have been working on a demo for a media player in an Android application, but I am encountering a problem. When I run my app, the song starts playing but does not play the full length - it just starts and immediately stops, going into the resume() stat ...

Is it possible to target only those divs within a class that wrap to a new line?

I currently have a series of 7 to 12 divs with the same styling, all floated to the left. Is there a CSS selector that can target the ones flowing onto a second row? I doubt this is achievable with standard CSS, so I'm curious if anyone has any jQuery ...

Struggling with incorporating a scroll loop effect and rotating div using the offsetTop property

Currently, I am working on a website that features a scroll loop effect, where reaching the bottom of the page seamlessly jumps back to the top, creating an infinite loop. My challenge lies in implementing an effect to rotate individual divs based on their ...

My attempt to implement a sticky position is not functioning as expected

I've encountered an issue with my code using bootstrap. Despite setting the top position to 0, it's still not working. Any ideas on why this might be happening? Here's the code snippet: <style> .background-nav { background: ...

Encountered an error in React where the declaration file for a module could not be located

New to Typescript and trying to incorporate a splitter into my project. I'm utilizing SplitPane from "react-split-pane/lib/SplitPane" and Pane from "react-split-pane/lib/Pane" in my Typescript project, but encountering an error: Could not find a de ...

The margin-top and margin-bottom properties are not functioning as expected

Check out this source: <div style="border:1px solid red; margin-bottom:10px">test blockA,</div>; <div style="border:1px solid red; margin-top:10px">test blockB</div>; There is consistently a spacing of 10px between blockA and ...

Move the box upwards and change it to grayscale when hovering over the image, then reverse the effect when the hover

As I hover over the image, my goal is to make a gray box appear at the bottom and smoothly slide up. While it slides up, everything it covers should turn grayscale. When I move my mouse away from the image, I want the gray box to slide back down and remove ...

Dynamic content that adjusts based on a multi-row element

I'm currently designing a webpage layout with a calendar on one side and a series of information-divs on the other. In desktop view, I want the calendar to span three rows like so: CAL DIV1 CAL DIV2 CAL DIV3 Right now, I am achieving this using neste ...

Converting CSV to JSON using JAVA (org.json) is not properly mapping headers to keys

The content of my CSV File is shown below: FID,OBJECTID,SHAPE,LAGE,GRILLPLATZ_ID,RESERVIERUNG,WEBLINK1,SE_ANNO_CAD_DAT "GRILLPLATZOGD.6748,6748,POINT (16.465255884594104 48.19018769574157),""22., Donauinsel, ca. 350 Meter stromab der Steinsp ...

Tips on capturing a string located in a JSON file using Java

I'm struggling with extracting the 'fulltext' parameter from a JSON file using Java. I am new to JSON and unsure of how to retrieve this specific value. Can someone guide me on how to access the fulltext parameter? Below is a snippet of the ...

Why are the items I have inserted inside my <div> tag not appearing on the screen?

What could be simpler than this: {this.state.dash ? <div className='dashWrapper slide'> HELLO </div> : null} I've tried everything, but nothing seems to show up inside the div. ...

What is the reason for getting a null return when attempting to access a resource within a Jar file using a URL

I am facing an issue with a specific Jar file called core.jar: META-INF/... com/... config myLog4j.xml schema The problem arises when trying to read/load a class located in com/my/company/MyLogging.class. Within the MyLogging class, I have the followi ...

Unable to detect any errors in the CSS file

Using RSpec to write some feature tests, I encountered an error in my application where a pre-purchased template with numerous styles is causing issues. Upon running the specs, the following error occurred: ActionView::Template::Error: Invalid CSS ...

IE6 disrupts stored layouts

I've encountered a strange issue with my design in IE6. It loads perfectly at first, but after reloading it a couple of times, everything suddenly collapses. The strange part is that when I upload an updated version, it fixes the issue, only to break ...

The integration of CSS into Laravel was unsuccessful

Below is the content of my index file located in views.admin: <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet&qu ...

Choose a record and remove it from the database without needing the primary key information

My task is to first select a record (which may not have a primary key) and then delete the same record. Here is the process : Select all records from the table. While iterating through each record using resultset.next(), retrieve one record at a time. D ...

CSS - Height not working properly on mobile device model iPhone 6

I've been working on a seemingly simple problem for some time now without success! The issue involves a <header> element with a height of 100px. When the screen size reaches a certain breakpoint (specifically targeting mobile devices), I need ...