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

Centering a Font Awesome icon within its parent element

Below is the code I am using: <div style="width:60px; height:60px; background-color: lightgrey;"> <a class="" href="javascript:void(0)" style="color: black; width: inherit; height: inherit;"> <i class="fa fa-lg fa-play" aria-hidden="t ...

Dynamic Binding of ng-model to DOM Element in AngularJS

I am facing a challenge with my web page where I need to dynamically attach ng-model attributes to some HTML elements that I don't have the ability to edit. What I want to achieve is to have AngularJS re-bind these attributes to the scope. You can fin ...

Adding Packages to AngularJS: A Step-by-Step Guide

Recently, I decided to dive into learning AngularJS and NPM on my own. Using the book Professional AngularJS by Diego Netto and Valeri Karpov as my guide, I successfully installed the application with Yeoman and ran it using Grunt. However, I've hit ...

Creating a default menu within a specific route in Ember.js is a crucial step in

I have created a JSBin code for my Ember.js application which can be found here: When I click on Item A, I want the ABCD menu on the left to remain visible and not disappear. Thank you. ...

Reacting to the dynamic removal of spaces

Is there a way to dynamically remove the space between removed chips and older chips in Material-UI when deleting one of them? <div className="row contactsContainer"> {contacts.map((contac ...

Eliminate any vacant areas within a container and shift the container, along with its contents, on the webpage

I want to eliminate the empty space within the container while maintaining some spacing around the black box, and ensure responsiveness. Additionally, how can I shift the container with its content downwards and to the right of the webpage, while still ke ...

Conceal Element without Eliminating from the Design

Need a solution: I have specific icons to display for certain elements, but not all. However, when hiding the icon, I want the spacing of the element to stay consistent. Is there a method to conceal an image within an element while preserving its allocat ...

How can I eliminate the time axis in FullCalendar's agenda view?

Is there a way for me to use multiple calendars and remove the time axis in the agenda view? I have tried using the axisFormat option to eliminate the numbers/content in that column, but I'm struggling to set the width to 0 or make any other adjustmen ...

angular.js:13920 Alert: [ngRepeat:dupes] Multiple occurrences in a repeater

I encountered an issue while attempting to parse a JSON file and map it in HTML. Here is the JavaScript code snippet: searhController.orderlogs.results = JSON.stringify(response.data); This is how it's implemented in Angular: <tr ng-hide="searh ...

Tips for choosing an <li> element with JavaScript

<style> .sys_spec_text{} .sys_spec_text li{ float:left; height:28px; position:relative; margin:2px 6px 2px 0; outline:none;} .sys_spec_text li a{ color: #db0401; height:24px; padding:1px 6px; border:1px solid #ccc; background:#fff; dis ...

Turning HTML into an image with the power of JavaScript

Utilizing html2canvas to convert a div into an image, everything is functioning properly except for the Google font effect. The image shows how it eliminates the effect from the text. https://i.stack.imgur.com/k0Ln9.png Here is the code that I am using f ...

Menu changes when hovering

I want to create an effect where hovering over the .hoverarea class will toggle the visibility of .sociallink1, .sociallink2, and so on, with a drover effect. However, my code isn't working as expected. Additionally, an extra margin is automatically ...

Utilizing data transfer in Angular

On my hotel website, visitors can view information about a hotel and click "book" to navigate to the booking page. Once on the booking page, users are prompted to enter their name and other details. However, I also want to include additional data from th ...

Designing a patterned rectangle filled with stylish text

I am relatively new to the world of HTML and CSS, and I am encountering a specific challenge with CSS. My goal is to design a section that looks like this: ---Image--- --Text-- ---Image--- --Text-- ---Image--- --Text-- ---Image--- --Text-- The ma ...

The Facebook login popup has been disabled

My current challenge involves using a Facebook app to authenticate my users. If the user is not logged in to Facebook (which I verify with FB.getLoginStatus()), I provide them with a button to log in. The issue I am facing is that the pop-up for logging in ...

Deactivate input areas while choosing an option from a dropdown menu in HTML

I've been working on creating a form and have everything set up so far. However, I'm looking to disable certain fields when selecting an option from a dropdown list. For instance, if the "within company" option is selected for my transaction typ ...

The text exceeds the maximum width of the table column

Currently, I am working with a table and utilizing the <col> tag to define column widths. However, I have encountered an issue where one of the columns, set at 5% width, contains a title that is 16 characters long, wider than the allocated 5%. As a ...

Enlarge an element to the extent of filling the list item

I am facing a challenge in expanding the a elements within this jsfiddle to fully occupy the li element. The use of display:block does not seem to be effective since I am utilizing a table for spacing. What steps can I take to achieve this while ensuring ...

Ordering by the scope function and then by a specific field can be achieved by following these

Is it possible to order by the result of getTotal() and then arrange by quantity in descending order? <!DOCTYPE html> <html ng-app="shop"> <head> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14 ...

How can I eliminate the tiny white square located beneath the scrollbar track?

`::-webkit-scrollbar{ width: 12px; } body::-webkit-scrollbar-track{ background: #f1e9e9; border-radius: 10px; margin-block: 0.1875rem; } ::-webkit-scrollbar-thumb{ background-color: #582965; border-radius: 10px; border: 3px so ...