Experience the magic of Vaadin Animations as elements gracefully fade out and disappear with the vibrant Valo

I'm attempting to fade an element away from the screen with the following code:

comp.addStyleName("fade-out");
.fade-out {
    @include valo-animate-out-fade(2500ms, 1000ms);
}

However, once the animation finishes, the element reverts back to its original state on the screen. Is there a way to receive a callback when the animation completes so I can remove it? Alternatively, is it possible to achieve this using pure SCSS?

I've noticed that once the animation runs once, it cannot be repeated by removing and adding back the style. Is this the expected behavior?

EDIT: The issue of not being able to rerun the animation was due to removing and adding styles in quick succession within a listener. This goes unnoticed by the client, preventing the animation from occurring. Resolved this by separating the removal and application of styles through server pushing.

EDIT 2: To remove the element after the animation, I managed to achieve it by initiating a thread, pausing for the duration of the animation, and then performing the removal. While effective, it does seem like a clunky solution. Are there any better alternatives?

Answer №1

While not focusing specifically on animations within the Valo theme, my answer delves into a more generalized approach to handling JavaScript functionalities in Vaadin, offering the ability to utilize callback functions on the server side. Although it utilizes jQuery, there may be potential to achieve similar results without it.

Here is an example class showcasing a callback function on the server side:

@SuppressWarnings("serial")
public class AfterFadeCallback implements com.vaadin.ui.JavaScriptFunction {
   @Override
   public void call(JsonArray arguments) {
      Notification.show("Faded!");                  
   }
}

Below is a simple demonstration of how to integrate the jQuery library with Vaadin's UI, along with instructions on invoking the above callback function from client-side JavaScript post-animation completion:

// Replace "jsquery.js" in the resource directory
// "VAADIN/scripts" (Maven Eclipse project src/main/webapp/VAADIN/scripts )
@com.vaadin.annotations.JavaScript({"vaadin://scripts/jquery.js"})
public class TestUI extends UI {

   @Override
   protected void init(VaadinRequest vaadinRequest) {
      com.vaadin.ui.JavaScript cjs = com.vaadin.ui.JavaScript.getCurrent();
      Button fadeButton = new Button("FADE");
      // An ID is required for JS identification
      fadeButton.setId("fadeButton");
      // Add Vaadin JavaScriptFunction to document 
      cjs.addFunction("org.example.javascript.AfterFadeCallback"
                           ,new AfterFadeCallback());
      fadeButton.addClickListener( click -> {
         // 'complete' defines the callback function after animation
         // This refers to the one added previously
         // However, it can accommodate any JS operations
         cjs.execute("$('#fadeButton').animate({opacity: '0.1'},"
                    +" {duration: 1500, complete: function() { "
                         +" org.example.javascript.AfterFadeCallback() } } );");
      });      
      setContent(fadeButton);
   }

...

}

Answer №2

Once the animation completes, the element reverts back to its original state on the screen.

.fade-out {
    @include animation(valo-animate-out-fade 2500ms 500ms forwards);
}

forwards indicates that the target will maintain the computed values from the last keyframe encountered during execution [1]. It is worth noting that I am not directly including valo-animate-out-fade because it is defined as:

@mixin valo-animate-out-fade ($duration: 180ms, $delay: null){
  @include animation(valo-animate-out-fade $duration $delay backwards);
}

I have observed that once the animation has run, it cannot be repeated by removing and then re-adding the style. Is this behavior normal?

Indeed. Keep in mind that Vaadin only sends updates to the client-side when changes occur. If you are removing and adding the style within the same listener call, no changes are actually communicated to the browser (thus, the animation won't reset).

Is there a way to receive a callback after the animation finishes so that I can remove it? Or perhaps achieve this using pure SCSS?

You cannot remove the component from the DOM using CSS alone (although it will stay hidden if you specify the animation to retain its final state). There is also an alternative approach discussed in [2] involving a Javascript extension, similar to the solution provided by @pirho.

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

The issue with the placement of the Bootstrap navbar-brand

My regular bootstrap navbar is presenting a problem where the item "navbar-brand" appears higher than the other items in the navbar, which seems illogical. This issue does not occur on the official bootstrap page and persists even when tested on jsfiddle. ...

Execute a test utilizing the Selenium WebDriver

I've recently started using Selenium Web Driver and I'm working on testing a Java test using it. When running the test class as a Java application, I encountered an issue with obtaining the ChromeDriver instance. Here's the code snippet wher ...

What is the best way to align three divs side by side using HTML?

Hi there! I need help figuring out how to display 3 div elements inline with each other without resizing when the browser size changes. Can anyone provide some guidance on this? This is how it should look like: https://i.sstatic.net/pBRZr.png Code: bod ...

Why do my padding and font size fail to match the height of my container?

When setting the height of my boxes to match the height of my <nav>, I encountered overflow issues. Despite using a 10rem height for the nav and a 2.25rem font, calculating the padding as 10-2.25/2 didn't result in the desired outcome. Can someo ...

Having trouble with Image and Css not displaying correctly when using CodeIgniter 3 with DomPDF?

I'm currently utilizing CodeIgniter 3 and dompdf to convert an HTML view into a PDF. While I am able to successfully convert the HTML to PDF, the proper styling is not being applied. All necessary CSS files have been included as custom design in the v ...

Function for calling a CSS callback with jQuery

I am currently working on enhancing my search bar using jQuery, and I am also looking to hide the navigation links. Here is a snippet of the jQuery code I have been using. The code functions properly when focused. $(".searchBox input").focus(function(){ ...

Include previous input as a "phantom" thumbnail to the slider element of type "range"

https://i.stack.imgur.com/JnuCN.png Using a tutorial from w3schools, I have customized a regular range slider. The objective is to send a new value command to an external MQTT-based home automation system and display the previous value as a ghost-thumb in ...

Exploring the semantics of CSS documents

Picture this scenario: I have a massive CSS file with over 40,000 lines, like the one found at https://cdn.jsdelivr.net/npm/[email protected] /dist/semantic.css I need to sift through this file and specifically search for class definitions that inclu ...

Discover the secret to applying a gradient shade to the "border" element when it reaches full capacity with Vue's innovative Custom CSS package

Utilizing the package https://www.npmjs.com/package/vue-css-donut-chart#usage-with-all-the-available-props to create a "border" effect around images based on progress has presented a challenge. Specifically, achieving a gradient color for the border when i ...

"Transforming Images: Unveiling the Journey from Bitmap to

Within my project, I have a method for saving a specified Bitmap to the local gallery on my phone. Here is an example of how this method is implemented: Bitmap bmp = some_fancy_bitmap; imgeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), bm ...

What could be causing the CSS height percentage to malfunction?

I'm having trouble with some basic CSS that uses percentages. I've labeled everything and checked my code, but it still isn't working properly. Here's the CSS code snippet: .BoxHeight { height: 100%; } #Box { margin-top: 0%; mar ...

Tips for modifying the background color of an individual row within a table using the Document Object Model (DOM)

I am trying to change the color of each row in a table only if the text inside the 4th cell is "DELAYED". I have created a function for this purpose, but the color is not changing as expected... function assignColor() { //retrieve all tr elements from ...

Importance of Order in Java String Operations

Can you explain the concept of string precedence in Java? public class PrecedenceInStrings { public static void main(String[] args){ int x = 3; int y = 5; String s6 = x + y + "total"; String s7 = "total " + x + y; String s8 = " " + x + y + "total"; Sy ...

Error: Java Cannot Locate Class in Classpath with Wildcards

Upon running a scheduled program in the command prompt, I encountered the error message below: Exception in thread "main" java.lang.NoClassDefFoundError: org/quartz/ScheduleBu ilder Caused by: java.lang.ClassNotFoundException: org.quartz.ScheduleBuilder ...

Consistent height for responsive images

How do I maintain the same height and proportions of images? Setting a specific height like 70vh achieves the desired height but distorts image proportions: https://i.sstatic.net/8eJq2.jpg On the other hand, using height: auto; creates responsive and pro ...

Preserving form input after an unsuccessful submission: A simple guide

As a beginner in the coding world, I am currently working on creating a contact form using PHP. One of the features I've included is a reCaptcha that must be checked before submitting the form. However, if the user forgets to check the reCaptcha and h ...

What is the best way to access a JSON file using Javascript or JQuery?

If I have a JSON Object like this: {"success":true, "uploaded_url":uploaded_url} What is the best way to alert("uploaded_url") from it? ...

Tips for eliminating default classes from Mui Typography styling

I’ve been working on creating a Typography element and noticed some default MUI CSS classes added when debugging in the browser. I attempted to disable them by using empty arrays at the end of the sx prop, but it did not work as expected. In the image p ...

Encountering a NoSuchMethodError related to the com.google.common.collect.ImmutableMap.of method while executing Selenium tests

Whenever I try to execute the following code snippet: WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); I encounter the following error message: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableMap.of( java.lang.Object, ...

Create a fully responsive full-page image layout without relying on the body tag

Recently, I've been trying to figure out how to make an image scale up to fill the entire page without relying on the body tag. Using the body tag causes issues with other elements appearing over the image instead of below it, which is not the desired ...