Move the remaining blocks after deletion

Is there a way to create a seamless effect when removing an element? I am looking to incorporate a transition or slide effect when deleting a block and causing the blocks below it to move up smoothly.

const animateCSS = (element, animation, prefix = 'animate__') => {
  // Creating a Promise and returning it
  return new Promise((resolve, reject) => {
    const animationName = `${prefix}${animation}`;
    const node = document.querySelector(element);

    node.classList.add(`${prefix}animated`, animationName);

    // Removing classes and resolving the Promise after animation ends
    function handleAnimationEnd(event) {
      event.stopPropagation();
      node.classList.remove(`${prefix}animated`, animationName);
      resolve('Animation ended');
    }

    node.addEventListener('animationend', handleAnimationEnd, {once: true});
  });
}

function delete_comment(id_comment){
    console.log(id_comment);
    animateCSS('#comment_'+id_comment, 'fadeOut').then((message) => {
        $('#comment_'+id_comment).remove();
        // Sliding the remaining block
    });   
}
$( document ).ready(function() {
  $( ".comment_tools" ).on( "click", function() {
      var get_id = this.id;
      delete_comment(get_id)
  });
});
.comment_block{
    transition: all 1s;
     width: 100%;
     padding: 10px;
     display: inline-flex;
     margin-bottom: 5px;
     background: green;
}
 .comment_profil_section{
     width: 15%;
}
 .comment_content_section{
     width: 85%;
     padding-left: 10px;
}
 .comment_header{
     text-align: left 
}
 .comment_datetime{
     display: block;
     font-size: 12px;
     color: #FFFFFF;
     margin-top: -2px;
     margin-bottom: 10px;
}
 .comment_message{
     text-align: left 
}
 .comment_user_picture{
     border-radius: 50%;
}
 .comment_user{
     font-weight: 400 
}
 .comment_tools{
     float: right;
}
 .comment_tools > .fa-pen{
     margin-right: 25px;
     color: #57CBCC;
     cursor: pointer;
}
 .comment_tools > .fa-minus-circle{
     color: #CC5857;
     cursor: pointer;
}
 .comment_tools > .fa-check{
     color: #57CBCC;
     cursor: pointer;
     margin-right: 25px;
}
 .comment_tools > .fa-times{
     color: #CC5857;
     cursor: pointer;
}
 .loader_comment_block{
     position: absolute;
     right: 30px;
     display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
<div id="comment_section" style="text-align: center" class="col-md-4 mx-auto">
   <div id="comment_101" class="comment_block">
      <div class="loader_comment_block" id="loader_comment_block_101">
         <div class="loader-2 center"><span></span></div>
      </div>
      <div class="comment_profil_section"><img width="40" height="40" class="comment_user_picture" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"></div>
      <div class="comment_content_section">
         <div class="comment_header"><span class="comment_user">USER</span><span class="comment_datetime">10/02/2021 at 15:53</span></div>
         <div class="comment_message">AAA</div>
         <div id="101" class="comment_tools">DELETE</div>
      </div>
   </div>
   
   (Other comment blocks omitted for brevity)
   
</div>

Answer №1

My attempt at recreating a similar animation to the one in the provided link involved adding the following code snippet:

$(node).animate({height: 0,margin: 0, padding: 0}, 200);
. I also made changes to the CSS for the .comment_block class.

.comment_block{ 
    display: flex; 
}

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

The contents of an array will be modified when the corresponding array that holds its value is altered

I have encountered a puzzling issue that I can't seem to comprehend. Specifically, I am dealing with a service array as follows: this.awesombarservice.Selected = [{id:1, value="20180101"}],[{id:1, value="20180103"}] After initializing another array ...

Trouble with linking an external JavaScript file in HTML document

I'm having some trouble including an external JavaScript file in my HTML. I followed the steps but the pie chart is not showing up as expected. Can someone please take a look and let me know if I missed anything? Here's the link to where I got th ...

Can a single link have a customized background color and different properties set for when it is clicked on?

I need assistance with setting the background-color of this <ul> to none while also adjusting the link's background-color to black. Here is the CSS code I have used: a:link { background-color: black } And here is the HTML code snippet: <di ...

Guide on passing variables along the promise chain within a Node Express router

Upon reflection, I realized the difficulty of injecting or utilizing a variable inside the Promise scope without a surrounding object or a "this" reference to attach it to. ...

Unleashing the y-axis and enabling infinite rotation in Three.js

In my three.js project, I am utilizing orbital controls. By default, the controls only allow rotation of 180 degrees along the y-axis. However, I would like to unlock this restriction so that I can rotate my camera infinitely along the y-axis. As someone ...

How can I position four DIV elements to the right of each other inside a parent DIV?

I am attempting to align 4 divs next to each other within a parent div at specific positions. The proposed div structure is as follows (referred to as the maindiv): <div> <div>1</div> <div>2</div> <div>3< ...

The type does not have a property named 'defaultProps'

I have a Typescript React class component structured like this: import React, { Component } from 'react'; interface Props { bar?: boolean; } const defaultProps: Partial<Props> = { bar: false, }; class Foo extends Component<Props& ...

Using a for loop to cycle through an array and generate sibling div elements

I'm attempting to display the content of the gameTwo array in two child divs under the game2 element. However, the issue I'm facing is that the loop creates a child of a child on the second iteration. Could someone provide guidance on how I can a ...

Property '{}' is not defined in type - Angular version 9.1.1

Currently, I am working with Angular CLI version 9.1.1 and I am attempting to update certain data without updating all of it. form: UserInfo = {adresse : {}}; UserInfo.interface export interface UserInfo { id_user: string; username: string; em ...

Ways to create collapsible navigation bars in your website

As someone exploring client-side development, I may be misusing the term "collapsible" in my title. What I aim to accomplish in my web application is allowing users to collapse header bars into small chevrons and expand them back when necessary. I am on t ...

Angular 1 and Javascript offer a different approach than using lodash omit and the delete operator

I am facing an issue with a child component where I need to remove properties from an object. Normally, using Lodash, it should work with the following code snippet: this.current.obj = omit(this.current.obj, ['sellerSupportWeb', 'sellerSup ...

Bringing in a variable from a component that is dynamically imported

I have a dynamically imported (Map) component on my page. const Map = dynamic(() => import('../components/Mapcomp'), { ssr: false, }) In addition to the component, I also need to import a variable from it. const [taskImg, setTaskImg] = useS ...

The buttons are off-center on the page when the screen width is below 1199px, they should be centered instead of aligned to the

Using Bootstrap 5, I've successfully created a layout with aligned rows of buttons at 1200px and above. However, an issue arises at the XL breakpoint (1199px) where the buttons align to the left of the container instead of being centered. You can vie ...

What could be causing my jQuery $(this).next().removeAttribute to not function properly?

I am currently working on a file upload form that includes buttons like "Choose file", "Upload", and "Add other file". I am facing an issue where the "disabled" attribute is successfully removed from the first Upload button upon File Input change, but it ...

Having trouble with links, imported templates, and selections not functioning properly post file reorganization?

After setting up my jQuery to import universal template files into various parts of my website, everything was running smoothly. However, once I restructured my filing system, things took a turn for the worse. Now, not only is my SELECT dropdown malfunctio ...

What could be the reason for v-model not functioning properly?

Embarking on my Vue.js coding journey, I am currently following a straightforward online tutorial. Utilizing the vue-cli, I kickstarted my application and crafted a basic component named Test.vue. Within this component lies a simplistic input control conne ...

Clicking the table initiates several AJAX operations to run using jQuery

As I searched for a solution to my problem, I reached a turning point where I could finally define the issue at hand. My code utilizes jQuery and Ajax, which are triggered by clicking on a table cell. The result is a table that I refresh at regular interva ...

JQuery hover effect causes mouse pointer to flicker

I'm currently working on creating a mega menu using Bootstrap 4, and I came across this code: While the code works well, I wanted to add a slide down/slide up effect to reveal the dropdown content when hovering over the dropdown link. So, I included ...

Message displaying successful AJAX response

I'm currently updating my AJAX request to make it asynchronous, but I am wondering if there is an equivalent to var response = $.ajax({ in the success function. Previously, my code looked like this: var response = $.ajax({ type : "GET ...

Enabling communication between my React frontend and Express server

I currently have a Digital Ocean Ubuntu VPS set up with Apache, Node, and Mongo running. I can successfully retrieve data from my database using CURL on the server and my node backend is running on port 3000. For my React frontend, I am using Fetch and it ...