Animate a div sliding up from the bottom to reveal a hidden div using Angular animations

Upon viewing the screenshot provided, it can be observed that there is a tab located at the bottom of a webpage. The desired functionality is for this tab to slide underneath the <div> element containing the word "Test" using Angular animations. The challenge lies in creating a responsive design where pixel values cannot be utilized due to varying page sizes. Attempts have been made with percentage values, however, the issue persists as these values are relative to the tab container instead of the overall height.

View Screenshot

Component Implementation:

@Component({
   selector: 'app-test',
   templateUrl: './test.component.html',
   styleUrls: ['./test.component.scss'],
   animations: [
      trigger('tabState', [state('default', style({
            transform: 'translateY(0)'
            })
         ),
         state('open', style({
            transform: 'translateY(-100%)'
         })),
         transition('default <=> open', animate(500))
      ])
   ]})

export class TestComponent {
   state = 'default';
   onComeIn() {
      this.state === 'default' ? this.state = 'open' : this.state = 'default';
   }
}

HTML Layout:

<div class="mainContainer">
   <mat-toolbar color="primary">
      <div class="d-flex align-items-center justify-content-between">
         <span>Test</span>
      </div>
   </mat-toolbar>

   <div class="mainContentContainer">
      <div class="d-flex flex-column" style="height: 100%">
      <div>content</div>
   <div class="mt-auto">
      <div class="tabContainer" [@tabState]="state">
         <div class="tab" (click)="onComeIn()">Tab</div>
      </div>
   </div>
</div>

CSS Styles:

.tab {
   box-sizing: border-box;
   height: 4.2em;
   width: 33%;
   background-color: white;
   padding: 1em 1.2em 0.45em 1.2em;
   border-radius: 0.5em 0.5em 0 0;
   box-shadow: 0 0.05em #b7b7b7;
}

.mainContainer {
   width: 100%;
   display: flex;
   flex-direction: column;
   position: absolute;
   top: 0;
   bottom: 0;
   left: 0;
   right: 0;
}

.mainContentContainer {
   flex: 1;
   background-color: #455864;
}

Answer №1

The main issue revolves around the css styling:

I made a change to the default value of the tabContainer class like so:

.tabContainer {
  position: fixed;
  bottom: 0;
  width: 100%;
}

Subsequently, in the animation definition, I eliminated the bottom property and added the top one instead:

state('open', style({
  bottom: 'initial',
  top: '20px'
})),

You can view a live demonstration in the code editor by clicking here.

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

Dynamically instantiate a new JavaScript object from an existing class by using input from the DOM

How can I dynamically create a new object instance of a class in Javascript for HTML, where the name of the object is derived from an input element? For example... Let's say we have a class named myClass and an object instance named Chickens with a p ...

What is it about Kyle Simpson's OLOO methodology that seems to swim against the tide of Typescript's popularity?

Disclaimer: this post might come across as impulsive. Warning for Typescript beginners! Also, a bit of a vent session. Recently, I delved into the OLOO approach from the YDKJS book series within a Typescript and Node environment. // ideal JS syntax le ...

Differences between Typescript static methods and functions defined outside of classesWhen comparing Types

What distinguishes a static class method from a function defined outside a class in TypeScript, especially when visibility is not a concern? While there are differences in visibility from other classes and files, what factors should be considered when dec ...

Troubleshooting: The issue of importing Angular 2 service in @NgModule

In my Angular 2 application, I have created an ExchangeService class that is decorated with @Injectable. This service is included in the main module of my application: @NgModule({ imports: [ BrowserModule, HttpModule, FormsModu ...

What is the process of launching an Angular component in a new browser tab?

I have a large amount of data that needs to be displayed on the screen in a simplified list format for users to choose an item and view its details. Consider a component called SimpleListComponent, which will store the data and present a condensed view: ...

"Why does the function not work inside the template, but works when the logic is set inside the template

My logic was working perfectly -> for example: Everything was working fine until I tried to set my values inside ts and switch logic in ts.file component. But when I did it inside the ts file, it stopped working: It's not working anymore. Why i ...

Explore navigation breadcrumbs in Sharepoint 2013

Can someone please assist me with implementing navigation breadcrumbs into a SharePoint master page? I have already tried enabling breadcrumbs in my master page using SharePoint Designer, but it did not give me the desired result. What I am looking for i ...

Conceal the Ipad keyboard while still retaining the ability to input text using a customized keyboard

I need to create an input field where users can enter numbers using a custom "keyboard" created with CSS/HTML on the page. This means I don't want the iPad's keyboard to pop up. Most of the solutions I've come across involve removing focus f ...

The function res.status is not defined

Currently, I am in the process of integrating my upcoming app with Google Sheets. I have relocated the function that manages the post request to "app/api/sheets" as per the recommended documentation. import type { NextApiRequest, NextApiResponse } from &ap ...

How to Use WebDriverJS to Target Multiple Elements by the Same ID

For my latest project, I am tasked with creating a test using Selenium, WebDriverJS, and Jasmine. The test is for a function that shows the content of a specific div only when its associated button is clicked. The challenge is to hide all other elements wi ...

The Selenium XPath isn't able to find the modal

I'm trying to target this specific input field: `(name="BtnOK" value="TAMAM" class="BoxButtonOK")` using xpath after a modal popup appears. I can't rely on .FindByClass because there are identical classes on the main page, but I specifically ne ...

Separate key and value pairs into individual div elements for JSON display

I have a JSON object with numerous keys stored in a single long object that spans over 10,000 lines. I am seeking assistance on how to iterate through each key and display the key in one div and its corresponding value in another div using JavaScript. Alt ...

In MUI v5 React, the scroll bar vanishes from view when the drawer is open

Currently, I am working on developing a responsive drawer in React using mui v5. In the set-up, the minimum width of the drawer is defined as 600px when it expands to full width. However, an issue arises when the screen exceeds 600px - at this point, the d ...

The Angular2 component link imported in the core.module is not functioning properly

Adhering to the guidelines provided in the Angular style guide found at https://angular.io/styleguide#!#04-11, I have created a simple navigation setup. My app.component contains links like <a routerLink="hello">hello</a>, which work perfectly ...

What might be preventing combineLatest from executing?

Currently, I am attempting to run a block of code utilizing the combineLatest function. Within my translation library, there exists an RXJS Observable that is returned. Imported as individual functions are combineLatest, map, and tap. combineLatest(this. ...

Twitter Share Button not appearing within Bootstrap Accordion

Looking to incorporate a Twitter 'share' button within each accordion item in Bootstrap 4 when expanded. Currently, I can get the button to show up outside of the accordion but not inside. I suspect that the issue lies with the class=="collapse ...

What is the reason that the values in the select option only appear once it has been clicked on?

After loading or reloading the page, I am experiencing an issue where the select options do not appear on the first click and the values are not displayed until the second click. Any assistance would be greatly appreciated! I am still new to coding, so ple ...

Having trouble with the sx selector not functioning properly with the Material UI DateTimePicker component

I'm currently working with a DateTimePicker component and I want to customize the color of all the days in the calendar to match the theme color: <DateTimePicker sx={{ "input": { color: "primary.main&quo ...

How does a brand new installation of VSCode believe it comes pre-equipped with TypeScript capabilities?

Operating on Windows 10 Enterprise, After investing several hours and experimenting on various VMs, Interesting Observation #1 Upon opening a .ts file in vscode, it appears to be recognized as TypeScript 2.3.4 as per the screenshot provided below: http ...

How can the Singleton pattern be properly implemented in Typescript/ES6?

class Foo{ } var instance: Foo; export function getFooInstance(){ /* logic */ } or export class Foo{ private static _instance; private constructor(){}; public getInstance(){/* logic */} } // Use it like this Foo.getInstance() I would ...