What is the best way to place a div on top of another div with a smooth

I am trying to achieve a specific effect where depending on certain conditions, one div appears overlapping another div from the right side. Below is the code I have been working on:

  const [loggedIn, setLoggedIn] = useState<boolean>(false);
  const [hasConfirmedAccount, setHasConfirmedAccount] = useState<boolean>(false);

  return (
    <>
      <div style={{ width: "100%" }}>
        <div style={{ float: "left", width: "50%" }}>
          <div
            style={{ width: "100%", height: "100vh", backgroundColor: "#fafafafa" }}
          ></div>
        </div>

        <div id='notLoggedIn' style={{ float: "right", width: "50%" }}>
          {!loggedIn && (
            <div>
                WHEN LOGGED IN === TRUE
            </div>
          )}

          <div
            style={
              loggedIn && !hasConfirmedAccount 
                ? { width: "100%", transition: "ease-in-out 5s" }
                : { display: "none" }
            }
          >
            <div id="notConfirmedAccount">WHENE LOGGED IN === TRUE AND hasConfirmedAccount === FALSE</div>
          </div>
        </div>
      </div>
    </>
  );

The current functionality works as expected, however, I am facing an issue when transitioning between divs with different IDs. I am looking for a way to create a smooth leaving effect of the div on the right side that overlaps the previous div.

If anyone has any suggestions or solutions, I would greatly appreciate it!

Answer №1

  1. add animate.css library by running the command $ npm install animate.css --save animate.css

2.include "./animate.css" at the top of your component or project

3.simply add the name of the animation as a className to your div element like so:

<div className={style.forgot} className='animate__animated animate__fadeInDown'>

also, remember to manage the visibility of your div using state

Answer №2

Enhance your React app with the power of animation using ReactTransitionGroup and ReactCSSTransitionGroup

With the ReactTransitionGroup add-on providing a low-level API for advanced animations, and the ReactCSSTransitionGroup add-on simplifying the implementation of basic CSS animations and transitions, you can easily bring dynamic movement to your components.

Find out more about adding animation to your React project 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

Adapting to more user inputs in accordance with the feedback received from the AJAX response

Two user inputs are being received: area time Utilizing this information, the available restaurants in the specified area during that particular time are displayed. In addition, all the cuisines offered by these restaurants are displayed as checkboxes. ...

Set a background image URL for a specific division inside a template

I have a drawPlaceDetails function that populates an HTML template with values. The getPhotoURL() function retrieves a URL link to an image, which I am trying to assign to the background-image property. However, the div remains empty without displaying the ...

I have image paths stored in my mySQL Database, how can I showcase them on my website?

As a beginner, I'm embarking on a learning journey where my aim is to showcase images from my database alongside other content within the same row in my HTML. Below is the JavaScript code snippet from my HTML file: <script type="text/javascri ...

Is browserHistory.push ineffective in react.js?

I am currently working on a React ecommerce website. I have encountered an issue in the login component where, upon clicking the submit button on the form, the system is supposed to check if the user is authenticated using useEffect. If the user is authent ...

Utilizing Next.js to Import a Function from a Path Stored within an Environment Variable

I'm having trouble importing a function whose path is stored in an environment variable Current import statement: import { debug } from '../lib/site-A/utils' Expected import statement: import { debug } from process.env.DEBUG_PATH In my ...

What is the right height and width to use in CSS?

I find it challenging to decide when to use rem, em, px, or % in web design. Although I know the definitions of each unit, I struggle with knowing the appropriate situations to utilize them. What guidelines should I follow to determine which one to use? ...

Can the height of an input element be set to zero?

Currently, I am utilizing CSS transitions to adjust the height of an input element from 40px to 0px in an attempt to make it disappear. While this technique works effectively for images and yields a satisfactory result, it seems to fall short when applied ...

How to set a custom background image for the Django admin panel

I am struggling to display a background image in the Django admin site. Despite researching multiple solutions, none of them seem to work for me. All I want is for the background to be visible behind the admin site. I have a file named base_site.html. {% ...

What is the best way to set the first radio button as the default selection in Material UI?

The challenge I am facing involves a set of radio buttons representing dates from today to 30 days in the future. When a radio button is selected or active, it changes the background color. However, I would like the default selection to be the first radio ...

What could be causing my Fetch GET Request to hang in Node.js?

Having trouble with the getDocuments request in my code. It never seems to complete and stays pending indefinitely. What could be causing this issue? App.js import React, { useState, useEffect } from 'react'; import Grid from './Grid'; ...

Upon initialization, navigate to the specified location in the route by scrolling

My page has various components stacked one after the other, such as: <about></about> <contact></contact> I am utilizing the ng2-page-scroll to smoothly scroll to a particular section when a navigation link is clicked. However, I a ...

Steps to include a horizontal divider in the footer section of an angular-material table

Is it possible to add a line between the last row (Swimsuit) and the footer line (Total)? If so, how can I achieve this using Angular 15? https://i.stack.imgur.com/581Nf.png ...

Tracking progress in a Rails job using Coffeescript

Recently, I came across a helpful gem called this gem, which allows for the seamless integration of bootstrap progress bars and the delayed job gem. The example provided by the creator uses .haml files, but since my project utilizes erb and coffeescript, I ...

Tips for retrieving middlewares from getDefaultMiddleware without triggering the deprecation warning

I have opted for a unique setup to initialize the redux store without using the configureStore method from redux-toolkit, with the intention of dynamically injecting reducers at runtime. import { createStore, combineReducers, applyMiddleware, createImm ...

Enhancing Your NextJS Website: Implementing a Full Page Background Image

I am facing an issue with adding a background image to my welcome page in NextJS. The problem seems to be related to how NextJS renders components inside a master component with a class of "__next". As a result, when I try to add a full-page background i ...

What is the best way to transmit a React context from a lower scope to a higher scope in React?

I have specific requirements regarding database and authentication contexts, as shown below. Please disregard the language aspect, as that is not a concern for me. root.render( <Router> <LangContextProvider> <DBContextContext ...

Vue 3 feature: Click the button to dynamically insert a new row into the grid

Just starting out in the world of coding, I've zero experience with Vue - it's my introduction to frameworks and arrays are currently my nemesis. In a recent exercise, I managed to display the first five elements of an array in a table after filt ...

What is the best way to integrate Vuejs while maintaining the integrity of the HTML5 structure

According to the official Vuejs documentation, when it comes to the mounting point: The designated element only acts as a mounting point. Unlike in Vue 1.x, the mounted element will always be replaced with DOM generated by Vue. Therefore, it is advised ...

What is the best way to obtain the id of a selected row using JavaScript?

I'm attempting to utilize the JavaScript function below to extract a specific cell value from a jqgrid upon clicking. Within the following function, #datagrid refers to the table where the jqgrid is located. $("#datagrid").click(function ...

What is the best choice for initiating async operations with Redux - should I go with Thunk, Saga, Observable, or Redux Promise Middleware?

After completing the Lynda tutorial on react native, I decided to delve into #Redux. However, when it comes to handling async flow in redux, the options are overwhelming: 1. Thunk 2. Saga 3. Observable 4. Redux Promise Middleware I'm stuck on which o ...