Create dynamic div animations triggered by changes in size of another div

Struggling to get this animation to function correctly.

I have a vertical scrolling page with various sized div elements that change based on the content. The problem is that when these size changes occur, the other elements are moving abruptly. I want to smooth out this transition.

This is part of a larger project (angular) and I cannot use any external libraries. I've created a jfiddle to demonstrate the issue.

$('.close').click(function () {
    $(this).parent().parent().height(0);
    $(this).parent().parent().slideUp(500);// in case if you want to move the second div up.

});

http://jsfiddle.net/zberQ/5/

In summary, the issue is not with the element whose height is changing. It's actually with the elements below it that are immediately adjusting in response to the height change.

Answer №1

Initially, I removed the line $(this).parent().parent().height(0); - not sure if it's necessary.

After that, I eliminated a .parent in the remaining code, and now it appears smoother with just a margin jump.

Check out the demonstration on this fiddle:

https://jsfiddle.net/Hastig/zberQ/17/

Here's the JavaScript snippet:

$('.close').click(function() {
    $(this).parent().slideUp(400);
});

And here's the simplified CSS:

.publication1 {
    background: red;
    color: white;
}

.publication2 {
    background: green;
    color: white;
}

.publication3 {
    background: blue;
    color: white;
}

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

Activate Jquery when the screen width is below 500 pixels

Seeking help with a code snippet that displays content upon clicking. I want this functionality to only be available when the screen or device width is 500px maximum. Can anyone guide me on how to achieve this? $(function () { $('.row1').hid ...

Looping through an array of images using JavaScript

Currently, I have a computer science test at school, and the main question is to create a traffic light that changes colors in a loop using arrays. I am facing some challenges with this question, but I believe I am close to solving it. Below is my code sni ...

What is the best way to incorporate the same partial multiple times with varying content in Nunjucks?

I'm working on several page templates that require the same partial to be included multiple times but with different content each time. I explored looping this, but the order might not always be sequential. Here's an example of how my page templ ...

Retrieving the length of an array from Firebase Firestore

Recently, I dove into a project that involves using Next JS and Firebase. After successfully storing data in Cloud Firestore, I encountered an issue when trying to retrieve the length of an array from the database. Below is an image illustrating the data s ...

Creating intricate JavaScript objects for JSON API integration can be accomplished by following these steps:

Here is a sample JSON structure used for querying an API: "order_items": [ { "menu_item_id": "VD1PIEBIIG", "menu_item_name": "Create Your Own", "modifiers": [ { "modifier_id ...

What could be causing the lack of styling in my Express application?

The styles are not rendering correctly on the specified route: 'http://localhost:5000/exams/add-new' However, they are working fine on the following routes: 'http://localhost:5000' 'http://localhost:5000/exams' 'http:// ...

Is it possible to obtain an image that is responsive while maintaining a specific height?

Currently, I am working on a page builder to create a shop. It's great that I have the ability to change the CSS on this project. However, I am facing a challenge with the responsive resizing of images in a 4 column row. Since the images have differe ...

One-line decorative border design

I'm experiencing an issue with a PNG image that I want to use as a border-image. The image is 10px x 1px in size, but when I try to use it, it only appears in the corners and doesn't repeat across the entire border. Can anyone help me figure out ...

What causes the button to move down when adjusting the font in a textarea?

I'm intrigued by the reasons behind this css snippet: select, input, textarea, button { font:99% sans-serif; } that causes the 'submit' button to be pushed below the textarea and positioned at the bottom left corner on this particular ...

Is the "mocha" command line tool requires quotation marks for specifying test files?

Here are some examples of npm scripts: "scripts": { "test": "mocha tools/testSetup.js src/**/*.spec.js" } "scripts": { "test": "mocha tools/testSetup.js 'src/**/*.spec.js'" } "scripts": { "test": "mocha tools/testSetup.js \"src/**/* ...

Understanding Escaped JavaScript Syntax

Looking for help parsing a string into a JSON object and converting it to a javascript array. Here is the initial string: "[{\"items\":\"nut\",\"sales\":6,\"prices\":10},\n {\"items\":\"bolt&bsol ...

Listen for the chosen choice

What is the best way to display a chosen option in PHP? I have set up an HTML menu list with options for "Buy" and "Sell". I need to output 'I want to buy the book' if someone selects "buy", or 'I want to sell the book' if someone pick ...

"Uncaught ReferenceError: $ is not defined - $function()" error in JavaScript/jQuery

When attempting to execute a JavaScript/jQuery function, an error is encountered when using Firebug: $ is not defined $(function()". The issue arises from the placement of the JavaScript code within a file named core.js that is referenced by index.php. W ...

Is there a way to synchronize the autohide duration for both the LinearProgress MUI and SnackBar components?

Can someone help me align my SnackBar with the LinearProgress so that they both have an auto-hide duration of 4 seconds? I've been struggling to figure it out for hours and haven't found a solution yet. Could the issue be in the useEffect part of ...

Establish a field alias with boundaries in AngularJS

I am currently working with a JavaScript object and attempting to display and edit its properties using templates. Here is a simple example: <div ng-init="friends = [ {name:'John', age:25, gender:'boy'}, {nam ...

Parsing the JSON string from PHP using JSON.parse resulted in an unexpected and strange array

I've encountered a challenge when trying to transfer a JSON object from the server to client-side JavaScript. I fetched rows of data from a MySQL query and stored them in $result. Below is the code snippet: var json = '<?= json_encode($resu ...

javascript - developing a neutral constructor

Similar Question: Constructors in Javascript objects I am exploring the concept of creating classes in JavaScript. I am struggling to grasp it fully. Now, I am curious if it's possible to create a constructor in JavaScript, similar to what can b ...

The element cannot be clicked at this point as another element would intercept the click:

Having an issue with clicking a button at the top of the page. The CSS selector works fine in my local Eclipse environment, but when trying to run it on Jenkins server on my local machine, it fails with an error stating that the element is not clickable. T ...

Do you require a lightbox for a white text box set against a semi-transparent black background?

Currently, I am in the process of developing a Chrome extension that will be compatible with my Android app. As part of this development, I need to code the HTML/CSS for the extension. The main functionality of the extension allows users to add tags to a s ...

Sass flex order has no effect on elements that are generated

I encountered an issue with the rendering of SVGs in my project. Currently, they are displayed correctly in desktop mode, but in mobile portrait mode, I need to change the order of one specific SVG element within the row. To achieve this, I decided to use ...