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

Modifying Copyright Feature in Footer

I am attempting to implement this function within my dark-colored footer: import Typography from '@material-ui/core/Typography'; function Copyright() { return ( <Typography variant="body2" color="textSecondary" align="center"> ...

leveraging an AngularJS controller to handle a service promise within the view

When using an angularjs service promise in a controller, I faced some issues with integrating it properly into the view. Initially, my controller function looked like this: this.getTodos = function () { TodoService.getTodos().then(function (todos) { ...

Dealing with numerous radio buttons

Can someone assist with the issue of the "idDefault" values not changing in this scenario? <div class="form-group" > <label class="control-label">Select Colors : </label> <div ng-repeat = "color in colorlist"> <input type="radio ...

What is the best way to delete a CSS class from a specific element in a list using React?

I need to implement a functionality in React that removes a specific CSS class from an item when clicking on that item's button, triggering the appearance of a menu. Here is my code snippet. import "./Homepage.css" import React, { useState, ...

An alternative to using controllers in AngularJS is to utilize the $emit and $broadcast methods

I am facing a situation where the angular plugin I am using restricts language changes to the $scope within its controller at runtime. The problem arises when some controllers do not exist until the view is switched, but I need to ensure that the plugin&a ...

Issue with Angular HTTP API get request not reaching intended Express server function

I am facing an issue with my Angular application where I need to retrieve data from a MongoDB collection. The problem arises when I make two HTTP API calls ("query" and "get") from flConstruct to fetch data from the server. The "query" call works perfectly ...

Once you name the ng-app, it causes the code to malfunction

My application is functioning properly without any specified ng-app name, yet when I try to assign it a name in Angular, it does not work as expected. I am using Angular version 1.2.6. Here is an example of my code: index.html <!doctype html> <h ...

Google Chrome has trouble displaying the body element at 100% height

Having an issue with Google Chrome – the body element is not reaching 100% height. In my website samples, at 100% zoom when hovering over a menu element (such as "O nás"), I change the background color of the body element. However, in Chrome, the botto ...

The datatable does not adjust to changes in page size

My jsfiddle example showcases different card boxes, and I am currently focusing on making the 'Table 1' box responsive. However, I have encountered an issue: Check out my jsfiddle example here code If you open the jsfiddle with a large enough ...

Generating a hyperlink to a specific user ID within a data table

I'm facing an issue with the formatting of my simple table when trying to navigate to user.id. Is there a better approach to this or should I consider moving LinkToUser? All styling has been removed to avoid any conflicts. import styled from 'st ...

Unable to render Material Icons on Vue/Quasar web app hosted on Azure

I am facing an issue with my webapp built using Vue and Quasar. I added the necessary icon imports to my quasar-user-options.js file. import '@quasar/extras/material-icons/material-icons.css' import "@quasar/extras/material-icons-outlined/ma ...

Creating a fixed sidebar in Bootstrap 3 that spans the full width of the column

I'm working with two columns - col-md-8 and col-md-4. In the second column, I have a fixed sidebar that I want to be 100% width of the col-md-4 column. The black box in the image below represents the second column. Despite trying setting the width to ...

Hacking through external script injections into the browser

Curious about how certain software or programs are able to inject html,css,js into a web browser without the need for installing any extensions. Every time I open Chrome or Firefox, I'm bombarded with ads on popular sites like Google homepage, Faceboo ...

AngularJS is throwing an error of "TypeError: Cannot read property 'then' of undefined."

Within an AngularJS project, I am aiming to retrieve user data from those who sign in and utilize this data within an HTML form. To achieve this, I have a script called sessionService.js that sends requests to the server and receives responses. The follow ...

User class instantiation in livequery is initiated

Is it possible to initialize the user class in a live query? I have initialized the user class in my index.js and it shows up in my network inspector. However, when I attempt to query, nothing appears in the websocket. Below is the code showing how I init ...

Guide to customizing the CSS styles of various components within a Material UI Dialog

Let's take a look at this snippet for creating a Material Dialog in code: <Dialog open={this.props.open} onClose={this.props.closeAtParent} PaperProps={{ style: { minHeight: '75vh', minWidth: '75vw', ...

Discover the object in the initial array that is not included in the second array using AngularJS

Imagine having these two sets of objects: first set: [ { id: "123", title: "123", options: [] }, { id: "456", title: "456", options: [ { id: "0123", t ...

Trouble arises in next.js containers when their content exceeds the specified limits due to @media rules adaptation

I've been working tirelessly for the past 2 days to resolve an issue with my next.js project. This is my first time using this technology and I feel like I might be overlooking something crucial. The problem revolves around three layers (as seen in t ...

Encountered a problem with Vuetify's sass variables

I am currently working on my Vuetify3 project where I need to customize a select dropdown from a library to match the style of Vuetify's select dropdown perfectly. After inspecting Vuetify's select box, I decided to replicate its styles by using ...

What is the process for exporting a class and declaring middleware in TypeScript?

After creating the user class where only the get method is defined, I encountered an issue when using it in middleware. There were no errors during the call to the class, but upon running the code, a "server not found" message appeared. Surprisingly, delet ...