AngularJS App with CSS transitions to smoothly fade in content and expand outer div

I have a project using angularjs, and I am looking to incorporate fade-in effects on the content when data is received. Additionally, if the data exceeds the minimum height of an outer div, I would like the outer div to expand slowly and smoothly.

To demonstrate this concept, I created a Fiddle that simulates data retrieval and display.

Check out the JSFiddle Demo here

I attempted solutions from an older question related to my issue, but I found them confusing.

In the demo, upon clicking "click to add", there is a $timeout before loading records with data. The data appears quickly, causing the outer div 'card' to expand rapidly in response to the inner content.

HTML Code:

<body ng-app="myapp">
  <div class="row">
    <div class="col s12 m6" ng-controller="controller1">
      <div class="card fill1">
        <div class="card-content">
          <span class="card-title">{{title}}</span>
          <div id="settings-controller2" parent="tippy" settings></div>
          <button ng-click="add()">
            click to add
          </button>
          <br/>
          <br/>

          <div class="filler">
            <div ng-show="loader" class="preloader-wrapper big active center-align">
              <div class="spinner-layer spinner-blue-only">
                <div class="circle-clipper left">
                  <div class="circle"></div>
                </div>
                <div class="gap-patch">
                  <div class="circle"></div>
                </div>
                <div class="circle-clipper right">
                  <div class="circle"></div>
                </div>
              </div>
            </div>
            <table ng-show="display" border="1">
              <tr ng-repeat="x in records">
                <td>{{x.Name}}</td>
                <td>{{x.Country}}</td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

AngularJS:

var myapp = angular.module('myapp', [])
  .controller('controller1', function($scope, $timeout) {
    $scope.title = "Controller 1";
    $scope.cache = false;
    $scope.records = [];
    $scope.display = false;
    $scope.loader = false;

    $scope.add = function() {
      console.log("adding");
      $scope.display = false;
      $scope.loader = true;
      $timeout(function() {
        $scope.records = [{
          "Name": "Alfreds Futterkiste",
          "Country": "Germany"
        }, {
          "Name": "Berglunds snabbköp",
          "Country": "Sweden"
        }, {
          "Name": "Centro comercial Moctezuma",
          "Country": "Mexico"
        }, {
          "Name": "Ernst Handel",
          "Country": "Austria"
        }, {
          "Name": "Lfds Atrfc",
          "Country": "Austria"
        }]
        $scope.display = true;
        $scope.loader = false;
      }, 1500);

    }
  });

If you have any questions or need clarification on my inquiry, feel free to ask.

Answer №1

To achieve this, consider starting with your .filler element hidden on page load by setting its opacity and height to zero. Add a transition: all 0.3s ease-out; property for smooth animation.

Once the content has loaded, add a new class to the filler element. In this new class, set opacity: 1; and max-height: 9999px; (note that max-height will adjust accordingly, but using auto for CSS height won't animate).

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

Managing audio in Ionic 3 when it overlaps

I am facing an issue with multiple buttons on a page, each playing an audio when clicked. The problem is that when I click on one button and then quickly click on another, the two audio files overlap. I need a solution to stop the first audio when a new bu ...

The Vue-generated #app div on my website is not expanding to fill the entire page as it should

I've been having trouble setting #app to 100% height. It seems like div #app isn't being recognized as a child of Body. This issue keeps occurring and I always have to find a different workaround. Is there a way to prevent this from happening en ...

Is it possible to apply a gradient to a table row in Internet Explorer?

Whenever I hover over a specific table row in my table, I want the background to transition to a linear gradient. The CSS code is pretty simple: tbody.row-links tr:hover { background: ...standard multi-browser linear gradient code... color: #333C3 ...

Navigating the itemlist HTML to extract and manipulate data in a Flask application

In my current project, I am attempting to retrieve a value from an array in Flask based on the user's selection. Additionally, I need to perform calculations on this value within Flask as well. Below is the code snippet: HTML Code: <div class="f ...

Linkify Method appearing in html.erb file displaying with HTML on the view

Apologies if this question seems basic, but I am encountering an issue when calling the following method on the @page instance variable. The view is displaying HTML tags instead of the desired content... module PagesHelper def linkify_page page rege ...

Conditional without any triggering event

I have a code that currently works using the click or keyup function. However, I am looking for a way to make it work without relying on keyup or click events. Is there a way to automatically change the line-height when the page is loaded? (Please note th ...

What happens when AngularJS returns an empty object after just one click?

This is a function that I call on ng-click. HTML <div class="col-md-offset-10"> <div class="form-group"> <a class="btn btn-default" ng-click="schedule ()">Add</a> </div> </div> JS $scope.scheduleid={}; va ...

"MongoDB fails to save changes when attempting to remove an item from an updated

I've been using Angular Fullstack for a web application. When I send my data using $http.post(), I include the following object: { title: "Some title", tags: ["tag1", "tag2", "tag3"] } However, when I edit the object and try to update it with $http ...

What could be causing my jQuery to not function on a separate domain?

Two of my websites have the same code, but one is functioning correctly while the other seems to be having trouble with the jQuery functions <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;char ...

The download attribute in HTML5 seems to be malfunctioning when used within a React environment

I am experiencing an issue where the download button is not working as intended. Instead of downloading the images, it is redirecting to another page. I have tested this on multiple browsers, including Chrome, Edge, and my mobile device, but the problem pe ...

What is the best way to maintain a div centered when the browser window shrinks smaller than the div's dimensions?

Is there a way to keep a div centered and create white space around it when the browser window is resized? I want this effect to happen whether the browser window gets larger or smaller. Currently, when the window size decreases, the left side of the div l ...

focusing on two different sections with a single hover effect

Is it possible to modify the styles of two different divs using CSS when hovering over one div? #down-icn { position: absolute; bottom: 0; right: 25px; color: #fff; -webkit-transition: color 0.25s ease; border-color 0.5s ease; -moz-transition: colo ...

Error message: "Issue encountered when trying to override styles in GWT DataGrid - ImageResource method value('cellTableLoading') not found"

Attempting to customize styles for the GWT DataGrid component following the instructions provided here. Here is my interface: public interface DataGridResources extends DataGrid.Resources { @Source({ DataGrid.Style.DEFAULT_CSS, "myDataGrid.css" }) DataGr ...

Viewing the details of a checkbox option

I have encountered a situation where I need to handle detail rows within a table that contain checkboxes for selection. The desired behavior is: 1) When clicking on the detail row image, it should expand to show the details of its parent row without sele ...

Steps for implementing target='_blank' on a <Link> tag with more than just an <a> element inside

I'm facing an issue where I need to open a new browser tab and redirect to a specific URL when a button is clicked. The problem arises when using an element other than an anchor tag inside the Next's <Link> element, as it seems to ignore th ...

Guide to activating Angular $http redirection during CORS requests

I am encountering an issue with my node/express application that has CORS enabled. Every time I attempt to do a POST request to /login on my app, it redirects to either /failure or /success. However, I always receive the following error message: XMLHttp ...

Troubleshooting the issue of autoplay not functioning in HTML5 audio

I'm facing a strange issue with my code - the autoplay feature for audio is not working as expected. Typically, whenever I insert this particular piece of code into a website, the music starts playing automatically. However, it seems to be malfunctio ...

Count the number of times an iteration occurs in AngularJS/JavaScript

I need assistance with my code snippet below, as I am trying to determine the count of all instances where $scope.rm is equal to "failed" or when $scope.percentage is less than 50. angular.forEach(result1, function (value, key) { $scope.percentage ...

Creating interactive links with SVG map shapesWould you like to learn how to make

I'm currently working on a project that involves creating an interactive map of the United States. The idea is that when a user clicks on a state, they will be taken to a static page for that particular state (for example, Alaska). I need help figurin ...

Extracting information from JSON using arrays

I'm facing a bit of a challenge with this one. I've been trying to use jQuery on my website to update an element. It works perfectly fine without using an array of data in JSON, but as soon as I introduce an array of data, it stops functioning. I ...