The animation named "fade1" is functioning properly, whereas "fade0" is not working as expected

Is there a way to incorporate animations into the "Forgot Password?" element using JavaScript?

document.querySelectorAll(`button`).forEach(btn =>
  btn.addEventListener(`click`, () => {
    if (btn.id === 'login-btn') {
      forgotPassword.classList.add("fade1");
      forgotPassword.classList.remove("fade0");
      submitLoginInfo.textContent = "Log In";
    } else {
      forgotPassword.classList.add("fade0");
      forgotPassword.classList.remove("fade1");
      submitLoginInfo.textContent = "Sign Up";
    }
  })
);
.fade0 {
    animation: 1s fadeAway ease-out forwards;
}
.fade1 {
    animation: 1s fadeIn ease-in-out forwards;
}
@keyframes fadeAway {
    from {opacity: 1};
    to {opacity: 0};
}
@keyframes fadeIn {
    from {opacity: 0};
    to {opacity: 1};
}
<h1 id="submitLoginInfo">-</h1>
<div id="forgotPassword">thing</div>
<button id="login-btn">fadein</button>
<button id="not-login-button">fadeout</button>

While adding the fade1 class results in the expected behavior with the animations playing whenever the login button is clicked, the fading out animation of the message does not seem to work. Any insights on how to resolve this issue? (full code available at: )

Answer №1

Please ensure to specify the target opacity for your items in the class definition to avoid animating from 1 to 1.

document.querySelectorAll(`button`).forEach(btn =>
  btn.addEventListener(`click`, () => {
    if (btn.id === 'login-btn') {
      forgotPassword.classList.add("fade1");
      forgotPassword.classList.remove("fade0");
      submitLoginInfo.textContent = "Log In";
    } else {
      forgotPassword.classList.add("fade0");
      forgotPassword.classList.remove("fade1");
      submitLoginInfo.textContent = "Sign Up";
    }
  })
);
.fade0 {
    animation: 1s fadeAway ease-out forwards;
    opacity: 0;
}
.fade1 {
    animation: 1s fadeIn ease-in-out forwards;
    opacity: 1;
}
@keyframes fadeAway {
    from {opacity: 1};
    to {opacity: 0};
}
@keyframes fadeIn {
    from {opacity: 0};
    to {opacity: 1};
}
<h1 id="submitLoginInfo">-</h1>
<div id="forgotPassword">thing</div>
<button id="login-btn">fadein</button>
<button id="not-login-button">fadeout</button>

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

`user implemented object comparison within a set in unity (es6)`

I am facing an issue where I need to handle multiple values and ensure that only unique ones are used. With the use of node js and access to harmony collections through the --harmony flag, I have considered using a Set as a potential solution. What I am s ...

Is it possible for the shadow of a pseudo element to remain lingering behind its corresponding element?

I'm experiencing an issue where the shadow of the pseudo element :before appears in front of its associated element. Check out this JSFiddle link for reference <div class="rectangle"> <p>Lorem Ipsum</p> <a href="#" style ...

Loading Options into Dropdown Menu from XML using "text" and "value"

I have set up a dropdown menu that is connected to an xml file. However, I want the "value" of each option in the xml to be displayed within the dropdown as well. Here is an example of how I would like it to look: Doctor 1 Dentist 2 Vet 3 and so on. ...

Secure TypeScript Omit Utility for Ensuring Type Safety

I need to create a custom implementation of Lodash's _.omit function using plain TypeScript. The goal is for the omit function to return an object with specific properties removed, which are specified as parameters after the initial object parameter. ...

Challenges encountered when converting Javascript into a Django template

I am facing a challenge with converting an HTML file into a Django template. It appears that the main.js file is not functioning properly, yet there are no errors being displayed in the debug console. I recently transferred the files from my local filesys ...

Tips for adjusting the maximum width and content-based width for columns within an HTML/CSS table

I'm working on a simple HTML/CSS code featuring a container with two adjustable slots, controlled by a handler in the middle to modify the space each slot occupies. The first slot contains a table with fixed columns, automatic columns, and limited col ...

@mui/x-date-pickers styling for the DatePicker component

Despite numerous attempts, I have been unsuccessful in styling the @mui/x-date-pickers <DatePicker/> component. I've experimented with various methods such as sx={{}}, style={{}}, makeStyles(), .css with the !important rule, renderInput={(param ...

Utilizing PHP and JavaScript in a multi-page setting

Apologies for the length of this post in advance. I've been struggling with a coding issue for quite some time now and haven't been able to find a solution. To provide more context and help to those who might assist me, I'm including most of ...

Leveraging Backbone.js without using client-side JavaScript

Exploring the idea of using Backbone.js and node.js to develop a compact web application. The concept of sharing code between the client and server is quite appealing. The challenge arises when considering how users without JavaScript-enabled browsers (in ...

What steps can I take to ensure that the children of my dropdown menu do not trigger the focusout event of the dropdown itself?

It's frustrating how children inherit their parent's event listeners by default, even if they are added after the listener was created. This just seems counterintuitive to me. I only want to add a listener to the parent element, not to all of its ...

Tap on the Dropdown Menu to access the Responsive design feature

Currently, I am working on perfecting a responsive navigation menu. My goal is to have the drop-down menu appear when the menu icon is clicked, as opposed to the hover effect. I am utilizing a Google jQuery script, but I am unsure if the drop-down functi ...

An effective way to pass a value using a variable in res.setHeader within express.js

Attempting to transmit a file on the frontend while including its name and extension. var fileReadStream = fs.createReadStream(filePath); res.setHeader("Content-disposition", `attachment; filename=${fileName}`); fileReadStream.pipe(res); Encount ...

jqGrid - Error when the length of colNames and colModel do not match!

Whenever I implement the code below, it triggers an error saying "Length of colNames and <> colModel!" However, if isUserGlobal is false, no errors occur. The version of jqGrid being used is 4.5.4 receivedColModel.push({name:'NAME', index: ...

Creating unique geometric designs with three.js

Attempting to construct a polygon in three.js and here is the code used for it. function DeployZone(coordinatesList) { // Forming the polygon Shape { var material = new THREE.MeshLambertMaterial({ color: 0x00ffcc }); var faces = [0, 1, 2, 3, 4] ...

Searching for text in a Python Selenium input field and retrieving suggested values can be achieved by using certain methods and commands

When you type a term like "apple" into the search bar on , a dropdown menu with search suggestions appears. https://i.sstatic.net/pGxzt.png I am attempting to retrieve a list, dictionary, or dataframe of the values in that dropdown box. For example: { ...

Steps to effectively pass parameters in a function object literal

As a JavaScript beginner utilizing an object literal pattern, I am attempting to pass integers as min and max parameters to a function in order to retrieve a random number for use in another function called "interaction". However, I encountered the error m ...

Iterating through a JavaScript object

Just starting out with JavaScript and trying to figure out how to iterate through a JSON result that has been converted into a JavaScript object. const url = 'https://api.mybitx.com/api/1/tickers?pair=XBTMYR'; fetch(url) .then(res => re ...

Effectively handle multiple connections from nodejs to postgres using the pg library

I need to run a script that performs multiple queries using the pg library for managing connections. However, I am facing an issue where my program stops working when the connection pool is full and does not queue future queries. I have tried setting the p ...

Creating a like button using AJAX in Django

Is there a way to implement a like button in Django using ajax without the need for a page reload? I've tried setting up my HTML and Ajax function, but it's not working properly. <form method="POST" action="{% url 'video: ...

Having trouble getting PostCSS nesting to work with CSS variables in Tailwind CSS and Next.js?

I've been attempting to utilize PostCSS nesting alongside CSS variables, but unfortunately the CSS variables are not being converted at all. Instead, I am seeing Invalid property value in the DOM for CSS Variables. The tailwind.css file I have inclu ...