Using jQuery to smoothly fade in elements and slide them up with a delay

Seeking assistance in adding a slideUp effect to my set of posts/divs in Wordpress that currently fade in one by one using jQuery.

I want the posts to slide up and fade in simultaneously, similar to this example: where they animate on filter click.

I've tried different methods but can't seem to achieve the desired result. Here's the code I have:

HTML

<div class="fade-in-post-container">
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
</div>

CSS

.elementor-post {float:left; margin-right:20px;}
.fade-in-post-container .elementor-post { display: none; }

jQuery

jQuery(".fade-in-post-container .elementor-post").each(function(i) {
    jQuery(this).delay(500 * i).fadeIn(1000);
});

Check out the jsFiddle here: https://jsfiddle.net/shan_2000_uk/kugc7m61/16/

I attempted the following:

jQuery(".fade-in-post-container .elementor-post").each(function(i) {
    jQuery(this).delay(250 * i).fadeIn(1000).slideUp(1000);
});

Unfortunately, it's not working as expected... Thank you for your help!

Answer №1

Perhaps this is what you're looking for, but feel free to take a look at this jsfiddle example.

jQuery(".fade-in-post-container .elementor-post").each(function(i) {
    jQuery(this).delay(250 * i).fadeIn(1000,function() {
            $(this).delay(250 * i).slideUp(1000)
        });
});

Answer №2

If you're looking to achieve this effect using only CSS and no jQuery, the code snippet below might be just what you need. Give it a try and see if it works for you.

body {
  background-color: black;
  margin: 0;
}

.fade-in-post-container{
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  width: 300px;
}


.elementor-post {
  position: relative;
  border: 1px solid red;
  color: white;
  width: 100%;
  padding: 10px;
  text-align: center;
  animation: fadeIn 1s linear;
  animation-fill-mode: both;
}

.elementor-post:nth-child(1) {
  animation-delay: 1s;
}

.elementor-post:nth-child(2) {
  animation-delay: 2s;
}

.elementor-post:nth-child(3) {
  animation-delay: 3s;
}

.elementor-post:nth-child(4) {
  animation-delay: 4s;
}

.elementor-post:nth-child(5) {
  animation-delay: 5s;
}

@-webkit-keyframes fadeIn {
  0% {
    opacity: 0;
    top: 100px;
  }
  75% {
    opacity: 0.5;
    top: 0px;
  }
  100% {
    opacity: 1;
  }
}
<div class="fade-in-post-container">
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
</div>

Answer №3

You have the ability to animate without using a queue, allowing multiple animations to occur simultaneously:

jQuery(this).animate({ opacity: 0 }, { duration: 1000, queue: false });
jQuery(this).animate({ height: 0 }, { duration: 1000, queue: false });

Here is an example of working code:

$('#run').click(function() {
  $('.fade-in-post-container .elementor-post').animate({ opacity: 1 }, { duration: 4000, queue: false });
  $('.fade-in-post-container .elementor-post').animate({ marginTop: 0 }, { duration: 2000, queue: false });
});
.fade-in-post-container {

}

.fade-in-post-container .elementor-post {
  width: 25%;
  height: 50px;
  display: block;
  margin: 1%;
  border: 1px solid #000;
  float: left;
  margin-top: 300px;
  opacity: 0;
}

#run {

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<button id="run">Run effect</button>

<div class="fade-in-post-container">
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
  <div class="elementor-post">test</div>
</div>

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

What is the best way to arrange an array of objects based on a specific attribute?

Ordering object based on value: test": [{ "order_number": 3, }, { "order_number": 1, }] Is there a way to arrange this so that the object with order_number 1 appears first in the array? ...

Why is the text getting covered by the drop down menu?

I am currently working with bootstrap classes and I am facing an issue where the drop down menu is overlapping with the text. You can see the problem in the screenshot here: enter image description here <div class="collapse navbar-collapse" ...

The BeautifulSoup select method is unable to select attribute values containing white space

city = soup.select('a[href="/city/london d12"]') When running the code above, an error message was returned: ValueError: Unsupported or invalid CSS selector: "a[href=/city/london" I'm currently exploring if there are any workarounds or ...

The issue with Jquery Ajax not functioning correctly seems to be related to the Laravel Pagination feature

Attempting to retrieve records from a database table using Ajax and Laravel pagination. This is my user interface https://i.sstatic.net/RpF1B.png Code for displaying pagination buttons <div class="pull-right" id="inboxcount"> <div class=" ...

The overflowing issue with the Nextjs Tailwind Marquee Component is causing a display

I've recently developed a unique nextjs/tailwind component. This component displays an isometric marquee that scrolls horizontally. However, I'm facing an issue where the content overflows to the right and causes the page to become horizontally s ...

Enabling or disabling mouse scroll wheel function across various web browsers

I am facing an issue with enabling/disabling mouse scroll using two buttons: "disable_scroll" and "enable_scroll". The code for disabling scroll works perfectly fine: var cancelscroll = function(e) { e.preventDefault(); }; $("#disable_scroll"). ...

Stop the submission process by deactivating the button until a selection is made

Is there a way to prevent the submit button from being clicked until the user has selected or typed at least one value? <form name="forma" method="POST" action="used-results.php" id="apliforma"> many textboxes and dropdown menus <a oncli ...

Utilizing Python to dynamically create unique tags from deeply nested dictionaries through recursion

As part of my project, I am developing a unique dynamic template tool that can seamlessly integrate with any templating framework such as pugs and jinja. The goal is to create a demo that resembles the following structure: view! { div { p { ...

Creating an If statement to evaluate the state of a parameter

In my simple Graphics User Interface, when the user clicks on "move", a yellow rectangle div moves across the screen. Now, I am trying to implement an event based on the position of the rectangle on the page. For example, if the div is at 400px (right), t ...

``How can I easily navigate to the top of the page when changing routes in React Router DOM v6?

What is the best way to scroll to the top when a route changes in react router dom v6? In the past, I used a solution from this StackOverflow post to make my page automatically scroll to the top every time a route changed with react-router-dom v5. However ...

Is there a way to remove the highlight from a non-active block?

Hey friends, I need some help with my code. Currently, when I click on a table it gets highlighted, and if I click on another table, the previous one remains highlighted along with the new one I clicked on. How can I modify the code so that when I click on ...

Placing the toolbar of phpGrid at the top of the datagrid for easier access

I am attempting to relocate the toolbar and its icons to the top of the phpGrid Lite datagrid. I found this code in the phpGrid knowledge base: $dg->cust_prop_jsonstr = 'toppager:true,'; $dg->before_script_end = ' jQuery("#ord ...

Making modifications to index.html that is being hosted on GitHub Pages

Need to make a minor change to a website hosted on Github pages, specifically updating the title in the index.html file. Considering modifying and committing the change directly in the Github code editor for ease. Upon checking the repository's Sett ...

Is there a way for the React select component to adjust its width automatically based on the label size?

After defining a React select component, it looks like this: <FormControl> <InputLabel id="demo-simple-select-label">Age</InputLabel> <Select labelId="demo-simple-select-label" id=&quo ...

The save feature becomes dysfunctional after switching to the Material-UI dependency in a React project

After integrating the Material-UI dependency into my ReactJS code, I encountered an issue where the "save" functionality no longer works properly. Previously, when editing a task in my simple Todo list app, the new name would be saved successfully. However ...

What is the best way to trigger a unique modal dialog for every element that is clicked on?

I simply want to click on the state and have that state's specific pop-up appear. $("path, circle").on('click', function(e) { $('#info-box').css('display', 'block'); $('#info-box').html($(this ...

Is there a way to create a scroll down and scroll up button that is located outside of the scroll box

A game designer challenged me to create a custom scrollbar with unique up and down button styles, as well as a custom-looking scrollbar. I wanted to achieve this without using the native browser scrollbar on Windows in Google Chrome. https://i.sstatic.net ...

Connecting event logic to Bootstrap 5 dropdown clicks: A quick guide

Is there a way to add an "onclick" event to a Bootstrap 5 dropdown in order to execute application logic based on the selected dropdown item? The Bootstrap docs cover events for when the dropdown is opened and closed, but there doesn't seem to be a s ...

Adding a list without a specific order into a paragraph with the help of jQuery

Working on a client-side class, I am in the process of changing an XHR request and getElementById function to a jQuery ajax request along with jQuery document manipulation. The task at hand is to display descriptions of items available from "Rob's Roc ...

The card-img-overlay in Bootstrap 5 seamlessly integrates into the following div container

Currently, I am in the process of creating a painting website layout for my CS50 homepage. However, there seems to be an issue with the background-color: rgba(0,0,0,0.7); not aligning correctly with the images within the card-group. <div class="car ...