Having trouble getting my AngularJS animations to work, hitting a roadblock

Here is the code I've put together for you to review, with no official purpose in mind. I just saved this code to use at a later time.

<script>
  var apps = angular.module('myApp', ['ngAnimate']);
  
  //header
  apps.controller('headerCtrl', function($scope) {
     $scope.header = "Animating with AngularJS and";
 $scope.headerCode= "CSS3"
  });
  
  //footer
  apps.controller('footerCtrl', function($scope) {
    $scope.footerItems = ['Footer Item 1', 'Footer Item 2', 'Footer Item 3'];
  });
  
  //animate hide/show
  apps.controller('animateCtrl', function($scope) {
    $scope.testText = "This is just to test the animation effect!!";
$scope.toggleBox = false;
$scope.Toggle = function() {
   $scope.toggleBox = !$scope.toggleBox;
 }
  });
 
</script>
.hideShow.ng-enter,
{
  transition: 0.5s linear all ;
  -moz-transition:  0.5s linear all;
  -webkit-transition:  0.5s linear all ;
  opacity:0;
  
}

.hideShow.ng-enter.ng-enter-active
{
 opacity:1;
}

.hideShow.ng-leave 
{
 transition: 0.25s linear all ;
  -moz-transition:  0.25s linear all;
  -webkit-transition:  0.25s linear all ;
  opacity:0;
}

.hideShow.ng-leave.ng-leave-active
{
 opacity:0;
}
<div class="container-fluid" ng-app="myApp">

<header ng-controller="headerCtrl">
  <div class="jumbotron page-header">
  <h1>{{header}} <kbd>{{headerCode}}</kbd></h1>
  </div>
</header>


<!--MAIN CONTENT (animate)-->

    <div class="jumbotron" ng-controller="animateCtrl">
   <button class="btn btn-primary" ng-click="Toggle()">TOGGLE</button>
   <div class="hideShow"  ng-show="toggleBox"><h2>{{testText}}</h2></div>
   
</div>
    
 

   <!-- FOOTER -->
   <div class="navbar navbar-inverse navbar-fixed-bottom" ng-controller="footerCtrl">
   <footer>
  <ul class="nav navbar-nav">
 <li class="navbar-brand" ng-repeat="footerItem in footerItems"> {{footerItem}}  </li>
  </ul>
</footer>
   </div>


 </div>

The toggle functionality works correctly, but I've been struggling to get the animation to work despite trying various approaches. Can anyone lend me a hand with this? Thank you in advance!

Answer №1

It seems like the classes you are using for ng-show are incorrect.

You should be using the following classes instead...

.ng-hide-add.ng-hide-add-active
.ng-hide-remove.ng-hide-remove-active

If you're having trouble identifying the correct classes, try adding a longer transition time in your CSS and inspect the element as it transitions.

Additionally, make sure to include the transitions in the base class like this...

.hideShow {
  transition: .25s linear all ;
  -moz-transition:  .25s linear all;
  -webkit-transition:  .25s linear all ;
}

Here's a Plunker link for verification: http://plnkr.co/edit/JJBv9pk8CSqN7Mmv8Qcx?p=preview

For more information, keep in mind that .ng-leave/enter is typically used for ng-repeats when items change. Different types of elements have different classes associated with them.

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

Exploring the capabilities of AngularJS for efficient testing using Jasmine alongside mixpanel integration

Within my AngularJS application, I implement MixPanel for analytics by using the asynchronous script in my index.html file. index.html <script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script ...

Organizing MVC5 with Angular JS: How to Create an Effective Folder Structure

As someone new to Angular and eager to learn best practices, I'm wondering about the ideal folder structure for an ASP.NET MVC5 AngularJS application. MVC5 default layout - Controllers Folder - Models Folder - Views Folder ---> Action Name Folder ...

What is the best way to populate a dropdown menu by matching keys from an array within an ng-repeat

My JSON structure looks like this: 101 : "List": [ { "Name": "Pink" }, { "Name": "Black" } ] 102 : "List": [ { "Name": "Red" }, { "Name": "Yellow" } ] $sco ...

Make the current tab the active tab with the help of AngularJS

I have a set of five tabs that are functioning correctly. However, when I refresh the page, the active tab reverts back to its default state instead of staying in its current active state. Can anyone help me identify where I may be making a mistake? Here ...

Problem with CSS creating the Typewriter effect when the third line of text is added

I've been working on a website for my new company and I want to incorporate a typewriter effect on the main page. I came across a tutorial on Medium.com but I'm having trouble adding an additional span to the provided code. Take a look at the lin ...

Tips for incorporating unique images into each individual flex box

I am new to the world of coding, having just embarked on this journey less than a week ago. Following a tutorial by a developer on YouTube, I tried to add my own twist to the project in order to differentiate it from the original. However, I've hit a ...

When floated to the right, the element is being pushed onto the next line in Firefox

Within a div, there are four elements. I specifically want the last element to be positioned on the far right, so I applied float: right to it. However, in Firefox, the last element gets pushed to the end of the next line instead. This issue does not occ ...

Ensuring the accuracy of a personalized directive within a form

I have a challenge with validating a form that contains a custom directive, especially in cases where the scope is an isolate scope. In a regular scope, it's easy to validate, but how do we handle validation in an isolate scope scenario? Here is an ex ...

Display a fresh <p> tag when the condition in the if-statement is met

If you are looking for a questionnaire, check out this one. Now, I am interested in creating if-statements using HTML/CSS/jQuery to achieve the following scenario: Initially, only Question 1 will be visible. When the input matches a certain value like X, ...

Transform your traditional sidebar into a sleek icon sidebar with Semantic UI

I am working on customizing the semantic-ui sidebar. My goal is to have it minimize to a labeled icon when the toggle button is clicked. However, I am having trouble with the animation and getting the content to be pulled when I minimize it to the labeled ...

Is there a way to prevent users from selecting dates and times prior to today, as well as blocking out the hours of 9:00am

Users are required to select a date within the range of today's date and one month in the future, and a time between 9:00am and 9:00pm. How can I implement validation to ensure this? <div class="row"> <div class="col"> <label cl ...

Bootstrap tab content getting shifted downwards

Having an issue with the Tab plugin in Bootstrap on a particular page. The tab body is being pushed down 400px below the actual tabs. This behavior is only occurring on this specific page, while most other pages using the same plugin are functioning fine. ...

Utilizing AngularJS to fetch data from a database using JavaScript and displaying it dynamically on a webpage using the ng-show

I am attempting to retrieve data from my database and then utilize ng-show with that data. Here is the JavaScript code in my file : httpq.post('/data/instructor.asmx/PasswordAgain', postData) .then(function(data) { $scope.i ...

Alphabetic divider for organizing lists in Ionic

I am currently working with a list in ionic that is fetched from a controller and stored in localStorage. My goal is to add alphabetic dividers to the list, but I am facing some confusion on how to achieve this. Here is a snippet of the code: app.js $ion ...

Utilizing Bootstrap Classes in ReactJS: A Comprehensive Guide

Is it possible to incorporate Bootstrap classes in a React application without actually installing the framework? If so, how can this be achieved and utilized effectively? I would greatly appreciate your assistance with this matter. ...

The Safari browser restricts interaction with password inputs but allows interaction with other types of input fields

My password input field is styled like this: <input class="genericButton" id="login-password" type="password" name ="password" placeholder="Password"> While everything functions correctly in Chrome, I encounter an issue with Safari. When I try to i ...

Using CSS, the ability to scroll to the top of a page is restricted when an inner div expands to the top while using flex

While following a tutorial on YouTube, I encountered an issue where my expanding content, when exceeding the size of the window in a small screen view, prevented me from scrolling to the top. Interestingly, I could scroll to the bottom and back up to that ...

Creating an engaging layout with Bootstrap 3: Utilizing grid systems for video integration

I am facing an issue with resizing multiple videos within a Bootstrap grid. The problem is that the column size increases, but the video itself does not resize accordingly. In my CSS file, I have set the width and height of the gif-video class to 300 for ...

Tips for embedding a file within a text box in HTML and enabling users to make direct edits

I am currently working on a feature that allows users to open a .txt or .html file from their file explorer and paste the contents into a textarea for editing and saving purposes. My question is whether it's possible to read the file content and auto ...

Creating a jquery DataTable from HTML generated by angular $sce can be done by following these steps

I have created an Angular controller that takes data and generates an HTML table from it. The generated table is being displayed on the page. Now, I want to apply jQuery data tables using that scope variable. The variable contains the HTML code of the tabl ...