The background layer is the only thing that does not have any animation effects applied

While delving into Angular, I encountered a minor issue that has me stumped.

I successfully animated a div (similar to a snackbar), but the text within the div does not smoothly appear or disappear like the background layer.

Check out this image for a visual representation of the problem: https://i.sstatic.net/35p6t.gif

import { Component } from '@angular/core';

import { MyService } from './myService';
import { trigger, state, style, transition, animate } from '@angular/animations';

@Component({
  selector: 'snackbar',
  templateUrl: './snackbar.component.html',
  styleUrls: ['./snackbar.scss'],
  animations: [
    trigger('shrinkOut', [
      state('inactive', style({height: '*'})),
      transition('* => void', [
        style({ height: '*'}),
        animate(300, style({height: 0}))
      ]),
      transition('void => *', [
        style({ height: 0}),
        animate(300, style({height: '*'}))
      ]),
    ]
    )
  ]
})
export class SnackbarComponent {
  constructor(
    public myService: MyService,
  ) { }
}
div.snackbar {
  position: absolute;
  width: 100%;
  height: 40px;
  top: 0;
  left: 0;
  z-index: 1000;
  text-align: center;
  vertical-align: middle;
  line-height: 40px;
}
    
div.snackbar.success {
  background-color: #9f5a77;
}
    
div.snackbar.error {
  background-color: #f44336;
}
<div class="snackbar {{myService.currentService.type}}" *ngIf="myService.currentService" [@shrinkOut]>
  Some Text
</div>

Do you have any suggestions on how to synchronize the text with the background layer?

Answer №1

The translateY() CSS function moves an element vertically along the 2D plane.

If you're utilizing the height property, only the height of the div will be animated, resulting in only the background layer being affected, not the text itself.

Please inform me if this explanation resolves your problem or if you continue to experience any difficulties. :)

Answer №2

After some reflection, I was able to pinpoint my mistake. In order to animate the text along with it, I should be utilizing the transform property instead of the height property.

Therefore, replacing height: '*' with translateY(0); and height: 0 with translateY(-100%)

Using the height property solely animated the height of the div.

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

What is the best method for retrieving values from a FlexiGrid?

I'm having trouble finding information on how to retrieve a cell's value from a flexigrid. My goal is to fetch the value of the third column for every checked item (each row has a checkbox). While I have a function that successfully gets the ro ...

line of checkboxes aligned horizontally with the help of Bootstrap

My goal is to create a horizontal row of checkboxes within a form. I've been able to achieve a functional but unattractive version by using the following code: div.form-group(ng-show = 'avariable') label 1 input(type = 'checkbo ...

Using the CSS to set the alt attribute and title of an image based on its file name

Is it feasible to dynamically set the ALT and title attributes of an image element to match the file name? It seems like this could potentially be achieved using the CSS content property, although I am not very familiar with the process. For example: < ...

Tips for creating a validation section in a CRUD application using React.js

I have been working on developing a CRUD app using ReactJS. However, I am facing some challenges with the validation process as it does not seem to be working correctly and I am not receiving any results. As a beginner in this field, I would greatly apprec ...

Leveraging AJAX Response for Ending a Parallel Query

Imagine initiating an AJAX HTTP Request through jQuery to a PHP script on the back-end that interacts with a MySQL server. What if, during this request, you want to create a new one and halt the existing process on the server? The file front-end.php has t ...

Incorporating Jest alongside setTimeout and leveraging useFakeTimers

As I work with a TypeScript async function that requires a 1-second sleep between two statements, this implementation is in place: async function systemUnderTest(): Promise<void> { console.log("One"); await new Promise(r => { set ...

What is the best way to update the background color of a row in an AG Grid table when it is clicked

I'm struggling to dynamically change the background color of a row in an ag-grid table when it is clicked. I have attempted using getRowStyle and getRowClass, but those methods only work when the table is initially loaded. I then tried utilizing onrow ...

Discovering the method to identify the loading of images referenced through JSON data using AJAX

When a user visits a specific site on my web, a large number of images are loaded. To achieve this, I utilize a JSON file containing the image filenames and other pertinent information which is fetched through an AJAX call. The process unfolds as follows: ...

Need to transfer data from an Angular 5 application to a server-side file using PHP, but

I am experimenting with sending an encrypted variable from Angular to a PHP script for testing purposes. Below is the client-side script: ngOnInit(){ let user = "am"; let key = "pizza"; let enc = crypto.AES.encrypt(user, key); console.log(enc); let dec = ...

What is the process for adding JSON object data to an existing JSON file using an HTML input form?

I have a JSON file named "WordMeanings.json" on my computer with the following data: { "WordMeanings": [ { "bangla": "ei je", "example": "Hi there!", "english" ...

What are some techniques for concealing user input within xml files?

I don't understand, if the html code looks like this: <input type="hidden" value="123"> What would be the equivalent code in xml? I'm new to xml and I'm struggling with this element, if in html it uses type="h ...

Issue with jQuery .hover() not functioning as expected

The issue I'm encountering is just as described in the title. The code functions correctly on all divs except for one! $(".complete-wrapper-1").hide(); var panelHH = $(".file-select-wrapper").innerHeight; $(".files-button").hover(function(){ $(" ...

The breeze is puzzled by the altered being, unable to identify it

I am currently working on a breeze implementation that involves displaying properties from a location object on the UI. However, when I make changes to some properties and attempt to save them, breeze does not recognize the entity as being changed. Here is ...

Utilizing Regular Expressions as a Key for Object Mapping

Currently, I am facing a challenge in mapping objects with keys for easy retrieval. The issue arises when the key can either be a string or a RegExp. Assigning a string as a key is simple, but setting a regex as a key poses a problem. This is how I typica ...

Unable to modify the .Css file for the VueJs plugin

I've been utilizing the vue-js-modal plugin and inside, there is a style.css file. I attempted to customize the modal style by making changes to this file, but even after saving my modifications and running the application, the modal page still reflec ...

Unexpected Placement of CSS Grid Items

I am currently facing an issue with aligning items in a nested grid using grid-column/grid-row assignment. After setting the template with grid-template-rows:/grid-template-columns, I expected the $50 and Give Now items to appear on row 3, with one in colu ...

Angular application navigation does not work as expected when the application is served in Express.js

I have an Angular 7 application that is running on an ExpressJS server. This is how the server part of the app is set up: app.get('/', (req, res) => { console.log(`sending...`); res.sendFile(path.join(__dirname, 'index.html') ...

What is the best way to ensure that empty strings are not included in the length of my array?

I have encountered an issue with a JSON file that I fetch. The array syllables is capable of holding up to strings max. However, when I exclude 2 words, I end up with 2 words and 2 empty strings. Nevertheless, my front-end still expects 4 "strings". So, it ...

Tips for presenting SVG symbols using Interpolation within Angular 7 from a JSON document

When it comes to displaying content in Angular 7 components, JSON is used. However, I have encountered a problem while trying to incorporate SVG icons from our UX team into the component using JSON. Using the img tag restricts me from applying a CSS class ...

Exploring the Scope of Iteration and Looping in jQuery AJAX

Can someone explain to me why the i variable still displays "5" in the code below, instead of incrementing from "1" to "4"? I suspect it may be a scope issue, but even after changing the scope of the i variable globally and within the DOM, the problem pers ...