Boost the height of a div in AngularJS using a sleek animation. Elevate or

I attempted to smoothly increase and decrease the height of a div using CSS animations, but I struggled due to my limited knowledge in this area.

Below is the code snippet:

<body ng-app="ang_app" ng-controller="ang_control01_main">
    <input type="checkbox" ng-model="myCheck">
    <div id="myDiv" ng-show="myCheck" class="animate-show animate-hide"></div>
</body>

var app=angular.module('ang_app', ['ngAnimate']);
    app.controller('ang_control01_main', function($scope) {

});

CSS Section:

.animate-hide {
-webkit-transition:all linear 1s;
-moz-transition:all linear 1s;
-ms-transition:all linear 1s;
-o-transition:all linear 1s;
transition:all linear 1s;
}

#myDiv {

    transition: .5s;
    background-color: lightblue;
    height: 100px;
}

#myDiv.ng-hide {
    transition: .5s;
    height: 0;
}

If you check out this site https://codepen.io/LFeh/pen/ICkwe, you'll notice how they effectively increase and decrease the div height when hovering over it. Can anyone provide guidance on achieving a similar smooth effect in my case?

Answer №1

Ensure that you have added the script reference to angular-animate.js for the expand and collapse transitions to work correctly. Below is a demonstration of how your code should look:

angular.module('app', ['ngAnimate']);
.animate-hide {
  transition: all linear .5s;
}

#myDiv {
  background-color: lightblue;
  height: 100px;
}

#myDiv.ng-hide {
  height: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular-animate.min.js"></script>

<body ng-app="app">
  <input type="checkbox" ng-model="myCheck">
  <div id="myDiv" ng-show="myCheck" class="animate-hide"></div>
</body>

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

Optimizing anti-aliasing for rotated images in Internet Explorer 10

Seeking a solution for implementing anti-aliasing on a rotated image with a wide border specifically in IE10 as shown above. I have experimented with -ms-backface-visibility:hidden which successfully addresses the issue in Chrome, however it does not seem ...

What is causing the auto-fill property in CSS Grid to malfunction when used in a vertical column direction?

I've been experimenting with the auto-fill property in grid rows, but it's not quite working as I intended. My goal is to create rows with a height of minmax(140px, 200px), however, what I'm actually getting is one row at 200px height and th ...

What is the best way to design a dynamic menu using HTML, CSS, and jQuery, where each li element gradually disappears?

Consider this menu structure: <ul class="main-menu"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> My task is to dynamically hide th ...

Modify the contents of a textbox by editing the text as you type

Text within the text box follows this format: login -u username -p password When entering this text, I want to substitute 'password' with a series of '*'s equal in length. For example: 'login -u <a href="/cdn-cgi/l/email-prot ...

Is it possible to use an SVG image as a border with a variable height in CSS

Check out this jsfiddle for my current project's nav setup. I want to center the logo in the middle of the nav with three links centered around it. However, I need the design to be responsive across various screen widths. Any advice on how to achieve ...

Chrome now supports clickable circular canvas corners

I have a unique setup with two canvases. I've customized them to be circular by utilizing the border-radius property. The second canvas is positioned perfectly within the boundaries of the first one using absolute positioning. This is where it gets e ...

expand the div to fill the entire page

I am currently working on a webpage at . I have set the body and html to 100% height, as well as #site_main with a height of 100%. However, I am facing an issue where the #footer is not sticking to the bottom on screens with higher resolutions, leaving som ...

Aligning content in the middle vertically with Bootstrap 3

While I understand that this question has likely been asked numerous times before, the solutions provided thus far do not seem to apply to my specific situation. This leads me to believe that there may be an additional factor at play in my content. <di ...

Remove Bootstrap-Table's box-shadow on the search bar's delete button

Is there a way to eliminate the box-shadow from the search box upon clicking on it? I am familiar with removing box-shadows from classes in CSS, but I am unsure of how to remove the box-shadow from a specific property like "data-search" within the tag. ...

What is preventing Angular UI-Grid from functioning properly in the latest Angular version 1.6.5?

I've encountered an issue where my Angular ui-grid fails to load data in the grid when using a more recent version of angular JS. It works successfully with older versions below 1.5.0, but not with 1.6.5. Furthermore, no errors related to the grid ar ...

Difficulty fetching css files on handlebars (express API)

Recently, I encountered an issue where the CSS styles were not being applied to my HBS code despite several attempts. The structure of my service is as follows: Service Controllers Models public css styles.css Routers Views index.hbs app.js pac ...

Parent table surpassing limits

Can someone help me with an issue I'm having regarding a table that is exceeding the width of its container? I've been struggling to find out what's causing this problem, especially because it seems to only happen in Firefox. Here's the ...

Validating state transitions in UI Router

Currently, I am in the process of setting up a multi-step wizard view to gather user input. The routing is functioning properly, but I am facing difficulties when it comes to validating the data received at each step before proceeding to the next. The cur ...

Printed pages featuring neatly organized two-column div layout

Forgive me if this question has already been asked, but I need some guidance: I am designing reports using HTML and CSS which are then converted into PDF format. The report requires a two-column layout on most pages, so I am using: <div class="two_col ...

What is the best way to ensure that an input group expands to fill the entire horizontal space

I am currently utilizing bootstrap 4 and have a responsive navbar for smaller screens. On this navbar, I am trying to implement a search input group that spans the full width from left to right up until the menu bar icon on the right side. You can view my ...

Selecting a field from a model based on the current locale in Angular: A guide

Exploring AngularJs. In my model, I have the following structure: animal: {name_en: "cat", name_de: "Kater", name_ru: "кот"} Now, I would like to display the appropriate field in the HTML template based on the locale. It should look something like thi ...

Creating an element that remains fixed once it reaches a distance of 50px from the top of the screen

Hey there! I'm working with an html div element that currently scrolls along with the page, but I was wondering how I can make it become fixed once it reaches a distance of 50px from the top of the screen. Any ideas on how to achieve this? Just to pro ...

What steps do I need to take to successfully integrate Firebase authentication with Angular2 FINAL?

After upgrading to Angular2 Final, I completed the migration project steps to transition everything over. Surprisingly, there were no errors during authentication; however, the issue arises post-authentication. Upon redirection back to the page, the authen ...

Hover over the first element to remove its class and replace it with a different element

I am attempting to develop a function that adds the class = "actived" to the first Element. This class has a CSS style that highlights the element in question. I have a list of 4 lines and I want the first one to automatically receive this class, while t ...

How to Fix Owl Carousel Not Displaying in Bootstrap 5

I attempted to use Owl Carousel version 2.3.4 with a CDN, but it doesn't seem to be working. Here is my code, but the carousel is not displaying. Thank you. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3. ...