What specific CSS property can be used to enhance the animation of hiding the width in the animate() function?

I'm working on a jQuery function where I have a list of elements in a ul, some are visible and some are hidden. When a li item is clicked, I want to hide any visible elements (by sliding them to the left) and then perform another action only if the first action was completed. How can I check if the first action was performed (i.e., if an element was animated by jQuery)? Here's what my HTML code looks like:

<ul>
<li>
     <div class="content_nav content_nav1">
     </div>
     <div class="content_el content_el1"> 
     </div>
</li>
<li>
     <div class="content_nav content_nav2">
     </div>
     <div class="content_el content_el2"> 
     </div>
</li>
</ul>

And here's the jQuery code:

for (var i = 1; i < 3; i++) {
    if (i != item_number) {
        var another_content = ".content_el" + i;
        var another_nav = ".content_nav" + i;

        $(another_content).animate({'width': 'hide'}, animate_duration);
        // Here I need to check if the above action was completed before proceeding with the next step
        $(another_nav).animate({'width':'show'}, animate_duration);
    }
}

I would really appreciate any help! Thank you in advance.

EDIT: So, the question now is: which CSS parameter does the following line modify?

$(another_content).animate({'width': 'hide'}, animate_duration);

Any insights would be helpful!

Answer №1

Assuming I have grasped your inquiry accurately,

To display another_nav only after the completion of the animation for another_content, you can pass a function as shown below:

$(another_content).animate({width: 'hide'}, animate_duration, function () {
   $(another_nav).animate({width:'show'}, animate_duration);
)};

Answer №2

When using the animate function, make sure to utilize the 'complete' handler. Visit this link for more information.

To run your function smoothly, implement the following code:

$(another_content).animate({'width': 'hide'} , animate_duration, function(){
    $(another_nav).animate({'width':'show'}, animate_duration);
})

It's important to note that the animate function will always "perform," so it's crucial to verify if the element is visible before adjusting its width:

if($(another_content).is(":visible")){
    $(another_content).animate({'width': 'hide'} , animate_duration, function(){
        $(another_nav).animate({'width':'show'}, animate_duration);
    })
}

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 benefits does a dynamic website like this offer compared to one that is purely AJAX-based?

There are two main categories of dynamic websites that I define: The first type utilizes languages like PHP to concatenate an HTML page and send it back to clients. On the other hand, the second type uses an HTML template where all interfaces provide JSO ...

What is the best way to update data by making API calls within store.js using Vuex?

I am in the process of integrating vuex into my project. I have familiarized myself with mutations and actions for updating state properties. My main inquiry is regarding the most secure and effective method to update state components by retrieving data fr ...

Transmit all Form Data via WordPress ajax

<?php add_action( 'admin_footer', 'my_action_javascript' ); function my_action_javascript() { ?> <script type="text/javascript" > jQuery(document).ready(function($) { var data = { action: 'my_action', ...

Replace the CSS styling with new code from different files

After downloading a large web template containing numerous CSS and JS files, I have successfully created a visually appealing website. However, there are still some minor details that I wish to modify, such as the font style and colors. The issue arises w ...

How to refresh AngularJS controller's JSON object data after making changes to the HTML using a text editor?

Currently, I am working on editing an HTML page that is linked with JSON object data using ng-bind. Interestingly, I have not utilized ng-model in this scenario. The code snippet can be found at the following link: http://plnkr.co/edit/vPYSpOtA96b497iQMHr ...

React state update not triggering a component re-render

I've been attempting to toggle the visibility of a div by clicking on another div, but I'm encountering an issue. The div becomes invisible on the first click only if it was visible initially. After that, it remains invisible and does not update. ...

Why does it seem like Typescript Promise with JQuery is executing twice?

Figuring out Promises in Typescript/JS seemed to be going well for me, but I've hit a roadblock. I've set up Promises to wait for two JQuery getJSON requests to finish. In my browser, when connecting to a local server, everything functions as ex ...

The Bootstrap navigation bar isn't displaying properly on mobile devices

Help! My Bootstrap navbar is not working properly on mobile view. The menu icon shows up but when clicked, no items are displayed. Here is the HTML code for my navbar: <header class="header_area"> <div class="main-menu"> ...

How to eliminate text located beneath an image using CSS

Is there a way to position the p tag directly below the user name and not beneath the image, all without relying on padding or margin-left? Here is the code snippet: <ul class="comments_list"> <li> <i> <img src=' ...

Create an element that can be dragged without the need to specify its position as absolute

I am having an issue where elements I want to drag on a canvas are not appearing next to each other as expected. Instead, they are overlapping: To make these elements draggable, I am utilizing the dragElement(element) function from https://www.w3schools.c ...

Scan through all <a> tags to identify those with the attribute target="blank". If any are found, use JavaScript to open a

Currently, I'm attempting to utilize JavaScript to open a link with the target="_blank" attribute. In order for this action to work, it's necessary to open a popup window within the web application; otherwise, it will be opened in an external br ...

How can I append a variable to the URL parameter in a jQuery $.get

I have been struggling with the $.get function in jQuery. My objective is to achieve something like this: $("#button").click(function(){ var value = $("#textfield").val(); alert(value); $.get('lookup.php?s=<?php echo $id ?>&q=' + value ...

The .each() function is invoked just one time

Here is the code snippet I am working with: function validateFormInputs() { isValid = true; var counter = 0; $('.form-input input[type="text"]').each(function() { isValid = isValid && validateInput( $(this) ); counter ...

Examining the false positive detection of an apparent visibility issue with

My goal is to check if the document is NOT scrollable using this code snippet: $el = document.documentElement const noscroll = $el.clientHeight === $el.scrollHeight // false console.log($el.clientHeight) // 977 console.log($el.scrollHeight) // 991 consol ...

Tips for utilizing an npm package in conjunction with Hugo

I created a basic hugo site with the following command: hugo new site quickstart Within the layouts/_default/baseof.html file, I have included a JavaScript file named script.js. Inside script.js, the code looks like this: import $ from 'jquery' ...

Can't get window.focus to work in JavaScript, but window.close is working fine

Goal: Notify the User before exiting the parent page if they have a Web Based Training Pop-up open. If they choose to stay on the page by clicking cancel, I want the focus to return to the pop-up. Currently, it remains minimized which is causing an issue. ...

Update the property prior to calling window.confirm()

Take a look at my code snippet: <a @click="destroy" :class="['button', { 'is-loading': deleting }]" > Delete </a> data: () => ({ deleting: false }), destroy () { this.deleting = true if (!confirm('Are ...

Resetting the Countdown Clock: A Transformation Process

I have implemented a countdown timer script that I found online and made some adjustments to fit my website's needs. While the current setup effectively counts down to a specific date and time, I now require the timer to reset back to a 24-hour countd ...

The chosen choice is not able to be shown within the option tag

When attempting to filter options using JavaScript based on a selected item, I'm encountering issues. If the selected element contains 'CONTINUE' or 'BRACKET', it should be split into an array by space and only the first two indice ...

Receiving the complete XML output post parsing and adding a node

let url = '/files/file.xml'; $.ajax({ type: "GET", url: url, dataType: "xml", success: parseResultsXML }); function parseResultsXML(xml) { let dom = $(xml); let item = $.parseXML("<SubNode><somevalue>new value< ...