Incorporating smooth sliding animation to ng-repeat elements

Our team has developed a custom widget in ServiceNow that displays a row of icons and reveals or hides additional details in a div when icons are clicked. Below is the structure of our html and client controller:

<div class="icons">
  <ul class="flex justify-content-center align-items-center">
    <li ng-repeat="item in c.data.linksArray track by $index">
      <a class="link" href="javascript:void(0)" ng-click="c.getInfo(item)">
        <i title="{{item.titles}}" class='fa {{item.icon}} fa-3x circle-icon'></i>
      </a>
    </li>
  </ul>
</div>

<div class="linkList text-center"
     ng-repeat="thing in c.data.linksArray track by $index"
     ng-if="thing.isVisible==true">
  <ul>
    <li class="m-b-sm" ng-repeat="link in thing.links">
      <a href="{{link.link_url}}">{{link.link_title}}</a>
    </li>
  </ul>
</div>
function($scope) {
    /* widget controller */
    var c = this;

    c.getInfo = function(item) {
        var isDisplaying = false;
        if(item.isVisible== true){
            isDisplaying = true;
        }

        for(var i=0; i<c.data.linksArray.length; i++){
            c.data.linksArray[i].isVisible = false;
        }

        if(isDisplaying == true){
            item.isVisible = false;
        }else{
            item.isVisible=!item.isVisible;
        }
    }

    console.log('icon-link-list');
    console.log($scope);
}

While the functionality works well, we aim to enhance user experience by incorporating a sliding effect to the .linkList class. The current behavior is too abrupt when the div appears after an icon is clicked. Is there a way to integrate a smooth sliding transition effect to the div using CSS?

Answer №1

To create a smooth animation effect using only CSS, apply the following code to the element that will be hidden/shown. This animation will trigger whenever the 'display' attribute in CSS changes. It is likely for the linkList element.

.linkList {
animation: slideFromLeft .2s;
    animation-timing-function: ease;
    animation-fill-mode: forwards;
    opacity: 0;
}
@keyframes slideFromLeft{
  0% {
      opacity: 0;
      transform: translateX(50px);
  }
  100% {
      opacity: 1;
      transform: none;
  }
}

Note: You may need to replace ng-if with ng-show in the linkList element.

Answer №2

According to the Documentation:

AngularJS animations rely entirely on CSS classes. If you have a CSS class assigned to an HTML element in your application, you can implement animations for it.

When ngRepeat adds a new item to the list, it will append an ng-enter class to the element. When removed, it will add an ng-leave class, and when moved, it will apply an ng-move class.

To learn more, visit

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

Using nextJS to establish a context within a Server Component and incorporating a new library

I attempted to incorporate Framer Motion into my project, but when I added it, an error occurred. The error message displayed was: TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Fo ...

Ways to assign dynamic widths to inner divs within a parent div automatically

I am working with divs <div id='top' > <div id='top-border' > </div> <div id='top-menu' > <jdoc:include type="modules" name="top-menu" style="well" /></div> </div> and adjust ...

Select the small image to reveal the larger overlay image

I have a grid of images and I want each image to expand into fullscreen when clicked. However, the JavaScript I am using is causing only the last image in the grid to overlay. How can I resolve this issue? Here is the code I am currently using: http://js ...

Error message: "Encountered 'Cannot Get' error while building Angular

I encountered an error when trying to run my Angular project in IntelliJ. Upon opening the browser on localhost, I received the message Cannot GET / Here are the steps I followed: Opened up the project Ran npm install -g @angular/cli@latest Ran gradlew c ...

Transform the array of strings

I'm currently working with an array that looks like this: ["[Date.UTC(2016,09,30),250500.00]","[Date.UTC(2016,09,29),255100.83]", "[Date.UTC(2016,09,28),255600.82]"] What would be the best way to transform it into a structure like this? [[Date.UTC( ...

Guide on how to align multiple divs at the center of a container using CSS

Experimenting with centering a divider in the style of Windows metro. .container { height: 300px; width: 70%; background: #EEE; margin: 10px auto; position: relative; } .block { background: green; height: 100px; width: 10 ...

Tips for ensuring an element stays anchored at the bottom even when the keyboard is displayed

I recently encountered a situation on one of my pages where an element positioned at the bottom using absolute positioning was causing issues when the keyboard was opened, as it would move to the middle of the page unexpectedly. While this may seem like a ...

I have configured my CSS styles in the module.css file of my Next.js application, but unfortunately, they are not being applied

I recently developed a nextjs with electron template application: Here is the link to my code on CodeSandbox: https://codesandbox.io/s/sx6qfm In my code, I have defined CSS classes in VscodeLayout.module.css: .container { width: '100%'; he ...

What is the process of editing a webpage to affect the display on a different webpage?

I am currently working on creating two webpages. One will serve as a customization page where users can upload images and input text, which will then be displayed on another page. I am wondering if it is possible to achieve this functionality using CSS and ...

Fade effects on hover with a changing background color

Here is the CSS code to be used: #onec-fourth:hover { background-color: #F36DE1; color: white; } I am looking to keep the background color and text color effects for 1 second after I move my mouse off the object (#onec-fourth). Currently, when I mov ...

Ensure the first column is fixed and all other columns have the same height

I have encountered an issue where the first column of my table has varying heights compared to the other columns, resulting in inconsistent row heights. Below is the code I am using: <div class="outer"> <div class="inner"> <table> ...

Exchange one HTML element with a different HTML element

I've been attempting to change an HTML tag using PHP or jQuery. The current default tag is: <li class="dropdown"> <a href="index.html" class="dropdown-toggle"> Home</a></li> My desired replacement for the above HTML tag is: ...

Tips for modifying the text color of radio button choices in HTML and CSS

I have set a black background image for my HTML page. How can I change the radio button labels/texts to white, similar to the questions? This is the code snippet that shows how it currently looks on the page: View Image <hr&g ...

Accessing data attributes using AngularJS

Trying to extract the data attribute from the following code: <button ng-click="EditPlayer(name, position, number, age)" id="btnEdit" class="btn btn-successes" data-playerid="{{player.id}}">Save</button> Within my angular controller: $scope. ...

A div positioned in front of a centrally-located div

Managing a website with numerous headlines can be a challenge. When a user clicks on a headline, a button located 10px to the left of the headline should appear. However, the catch is that the headlines must always remain centered, regardless of whether th ...

Encountering a 400 error in Application Insights

Today I discovered a problem with application insights. I am now receiving a 400 error when attempting to track an event: POST 400 (106: Field 'type' on type 'Device' is of incorrect type. Expected: string, Actual: undefined) No chan ...

What is the best way to ensure proper alignment of elements in a React application?

Currently, I am delving into learning react and antd by putting it into practice. My goal is to create a layout with a button and two input fields that have a 10px gap between them, while also displaying the titles of each field directly above them. To ach ...

Seeking Assistance with Customizing HTML Uniform Panels

Looking at the HTML provided, I have two requirements: Request: I need to center the green boxes regardless of their height, without having to adjust the top:-10px/bottom:-10px values when the height changes. Eliminate the fixed top/bottom value (as the ...

Updating view in AngularJS using Promises

I am currently facing an issue where I need to update the view of an Angular application from its controller using an ES6 Promise (fetch) resolved value. The challenge lies in the fact that Angular does not automatically update the view when my promise res ...

Utilizing GridFS for efficient file storage in MongoDB with the seamless integration of Mongoose and AngularJS

When I first started, I had very little knowledge on how to save a file to a NoSQL MongoDB using Mongoose and Angular. After extensive research, I discovered that I needed to utilize GridFS to solve my problem. The challenge was finding a detailed explan ...