Creating custom animations for ngShow and ngHide directives using ngAnimation

After following the lesson at https://docs.angularjs.org/api/ngAnimate, I managed to get the CSS-based animations working properly. However, I encountered an issue where all DOM elements using ng-show/ng-hide were affected by the animation. I only want a specific element to be animated, similar to the example below:

CSS:

.fade-in-out {
  transition: 1s linear all;  
  opacity: 1;
}

.fade-in-out.ng-hide {
  opacity: 0;
}

<div class='col-xs-12 col-ms-12 col-sm-12 col-md-12 col-lg-12 fade-in-out' ng-show='checked'><input type="text" name="first-name"></div>
<div class='col-xs-12 col-ms-12 col-sm-12 col-md-12 col-lg-12 fade-in-out' ng-show='checked'><input type="text" name="last-name"></div>

JS:

$timeout(function () {
    scope.checked = true;
}, 2000);

The current code affects all instances of ng-hide/ng-show, but I want it to specifically target the specified html objects only. This is important as I plan on creating a dynamically generated bootstrap form that needs to fade in individually. Since combining the inputs into one div is not feasible for my scenario, I am seeking a way to isolate the animation to certain elements. Any advice or solutions for this would be greatly appreciated as I am new to this technology.

Answer №1

To achieve the desired effect, utilize distinct ng-show conditions for each section within the code snippet.

<div ng-app="myApp" controller="myVm">

    <div class='fadeInOut' ng-show='!isCheckedFirst'>
        <input type="text" name="first-name">
    </div>
    <div class='fadeInOut' ng-show='!isCheckedFirst'>
        <input type="text" name="last-name">
    </div>

    <div class='fadeInOut' ng-show='!isCheckedSecond'>
        <input type="text" name="first-name">
    </div>
    <div class='fadeInOut' ng-show='!isCheckedSecond'>
        <input type="text" name="last-name">
    </div>

    <input type="checkbox" ng-model="isCheckedFirst">
    <input type="checkbox" ng-model="isCheckedSecond">
</div>

JS

angular.module("myApp", ['ngAnimate']);

angular.module("myApp").controller("myVm", function($scope) {
});

CSS

.fadeInOut {
  transition: 1s linear all;  
  opacity: 1;
}

.fadeInOut.ng-hide {
  opacity: 0;
}

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

when the AJAX request has a specific condition

When making an AJAX request, I want to pass data only if a certain condition is met. The "data: testobj" line represents a JSON object that will return {"name":"tom"} $.ajax({ type: "POST", url: 'test.asp', data: testobj, succes ...

Is it necessary to release an NPM package when creating a custom Javascript library for local use?

I want to organize my javascript utility functions in a central folder and access them from multiple projects. It appears that I am unable to import functions from outside the src file of my project. Do I need to create an NPM package? Must I duplicate t ...

Using Google Apps Script to input data into the next available row

Utilizing Google Apps Script, I am retrieving data from another spreadsheet and storing it daily in a sheet named "DATABASE". Although my current solution is basic, it keeps overwriting existing data. I wish to enhance the script to copy data from the imp ...

Implementing efficient loading and dynamic updates in web applications with Angular.js and php through

Currently, I am working on a project that requires lazy loading of images. However, a new requirement has come up which involves a server batch process pulling images from a database at regular intervals. These images must then be appended to the photos ...

Angular 2 Error: Unable to access the property 'value' as it is undefined

Whenever I click on the Submit button, this error pops up in the browser console. https://i.sstatic.net/57a5N.jpg In my application, I am attempting to retrieve information about the code uploaded by a Student. I am at a loss as to why this error is bein ...

How can we use PHP and jQuery to open a simple modal with data?

Here is a basic modal setup: <div id="info" style="display: none;"> <h3 class="title">User Information</h3> <table border="0" cellpadding="5" cellspacing="0"> <tr> <td width="50%" align="right ...

Why does React / NextJS throw a "Cannot read properties of null" error?

In my NextJS application, I am using useState and useEffect to conditionally render a set of data tables: const [board,setBoard] = useState("AllTime"); const [AllTimeLeaderboardVisible, setAllTimeLeaderboardVisible] = useState(false); const [TrendingCreat ...

When interacting with the iframe in an Ionic3 app, it suddenly crashes

Greetings! I have integrated a flipping book URL inside an iframe: <ng-container> <iframe [src]="eUrl" id="flipping_book_iframe" frameborder="0" allowfullscreen="allowfullsc ...

Discover the Maximum Total that is Below or Equal to a Specified Limit

Here is a function I am working with: var data = [12,23,14,35,24]; //debugger; function findMaxSum(dataArr, targetSum){ var currentSum = dataArr[0]; var maxSum = 0; var start = 0; for (var index = 1; index < dataArr.length; index++) { whi ...

Using AngularJS to send emails via the Gmail API

My goal is to implement a feature in my Angular controller that allows users to send emails. The idea is for users to authenticate themselves using their GMAIL accounts and send emails directly through the web application. Do you think this can be achieve ...

Browse through content without displaying the page title on the navigation bar and without the use of frames

When I sign into certain websites, I have noticed that the address displayed is often something like this: https://examplesite.com/access Even though all the links on the landing page are clickable and functional, their corresponding addresses never show ...

The external IP lookup service is showing a 404 error code

While attempting to retrieve the user's IP address from an external IP service, everything works smoothly on a PC browser but returns a 404 error on the device. Even after trying alternative external IP services, the same issue persists on the device. ...

Javascript continues to execute even after the designated element has been eliminated or substituted

I'm currently working on a WordPress auction site using WooCommerce that needs a countdown timer to display when a specific product auction is ending. Below is the JavaScript code for the countdown timer: const getElem = elem => document.q ...

Check if the div has been clicked, even if its child elements have also

Is it possible to check if both a div and its child are clicked using jQuery? $('div').click(function(e){ if(e.target.id == 'test') alert(e.target.id); }); I have a specific div with an id of #test in my HTML code, and wh ...

Is there a way to find the JavaScript Window ID for my current window in order to utilize it with the select_window() function in

I'm currently attempting to choose a recently opened window while utilizing Selenium, and the select_window() method necessitates its WindowID. Although I have explored using the window's title as recommended by other sources, and enabled Seleni ...

Build.js.erb requesting a partial script task

Struggling to make my create action function accurately in my rails app. The following two lines work as intended: $('#pit_form').remove(); //remove form $('#new_link').show(); //show new link again They successfully remove the form ...

Recording incoming audio from headphones programmatically involves accessing the audio input stream, which can be done by

I need assistance in creating a JavaScript application that can record incoming audio through headphones. I am able to record my own voice, but I am struggling to capture the audio of the other person speaking through the same headphones. ...

Is it possible to adjust the color of this AnchorLink as I scroll down?

Currently struggling to update the color of a logo as I scroll. While the navigation bar successfully changes colors, the logo remains stagnant. Here is the excerpt from my existing code: navigation.js return ( <Nav {...this.props} scrolled={this ...

Tips for testing a function within an AngularJS service using simulated data

Looking to write a Jasmine unit test for a specific function within an AngularJS service provider called shapesResolver. The goal is to create mock data for myObject and then test the function getObjectShape() using that mock data as a parameter. How can ...

Using ui-tabs with Ng-repeat to create both dynamic and static tabs

I'm currently working on creating a date tabs feature where users can click to add more tabs. Below is a snippet of the code I'm using: `<uib-tabset justified="true" class="ui-tab"> <uib-tab ng-repeat="date in dates track by $index" hea ...