Slow and choppy animations with jQuery

I've been struggling with a slow and choppy jQuery animation despite trying various techniques to improve its speed. I've attempted stopping existing animations before starting new ones, ensuring animations are only performed when necessary, and even incorporating jquery.gsap.js. Additionally, I've experimented with CSS animations but have yet to achieve the level of smoothness I desire. Does anyone have any suggestions on how I can optimize the performance of my animation?

For reference, here is the jsfiddle link.

<section id="vertical-strips">
    <ul>
        <li style="background-image:url(im1.jpg)">t1</li>
        <li style="background-image:url(im2.jpg)">t2</li>
        <li style="background-image:url(im3.jpg)">t3</li>
        <li style="background-image:url(im4.jpg)">t4</li>
        <li style="background-image:url(im5.jpg)">t5</li>
        <li style="background-image:url(im6.jpg)">t6</li>
        <li style="background-image:url(im7.jpg)">t7</li>
    </ul>
</section>
#vertical-strips {
    width: 100%;
    height: 100vh;
    max-width: 100%;
    overflow: hidden;
}

#vertical-strips ul {
    padding:0;
    margin:0;
    list-style: none;
    display: table;
    table-layout: fixed;
    width: 100%;
    max-width: 100%;
    height:100%;
    overflow: hidden;
}

#vertical-strips ul li {
    margin: 0px;
    display: table-cell;
    overflow: hidden;
    text-align: center;
    vertical-align: middle;
    font-size: 2vw;
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
items = $("#vertical-strips ul li");
items.each(function(i) {
    $(this).hover(function() {
        size = $(window).width()/items.length; 
        items.each(function(j) {
            if (j != i) {
                if ($(this).width() > size - (40.0/items.length) + 5) {
                    $(this).stop();
                    $(this).animate({width:size - (40.0 / items.length)},  "fast");
                }
            }
        }); 
        $(this).stop();
        $(this).animate({width:size + 40},  "fast");    
    },
    function() {}
);
});

Answer №1

Consider incorporating the "linear" easing option into the easings property, and possibly adjusting the $.fx.interval value before starting the animation.

$.fx.interval = 100;

items = $("#vertical-strips ul li");
     items.each(function(i){
        $(this).hover(
            function(){
                size = $(window).width()/items.length; 
                items.each(function(j){
                    if(j != i ){
                        if($(this).width() > size - (40.0/items.length) + 5 ){
                            $(this).stop();
                            $(this).animate({width:size - (40.0/items.length)},  "fast", "linear");
                        }
                    }
                }); 
                $(this).stop();
                $(this).animate({width:size + 40},  "fast", "linear");  
            },
            function(){
            }
        );
    });

Check out the code on jsfiddle here.

Answer №2

It's quite straightforward, just examine your animate() function:

$(this).animate({width:size + 40},  "fast");

The "fast" parameter in your code can actually be modified to any value. You have the flexibility to adjust the speed of your animation. Simply replace "fast" with "5," for instance.

View the example on Fiddle.

Refer to the documentation on animate's properties here.

Answer №3

Instead of categorizing between slow and fast, I simply set a time limit of 10 seconds.

Note: If you desire even faster speed, reduce the value to less than 10.

This approach may be beneficial for you.

CLICK HERE FOR WORKING DEMO

JavaScript Code

items = $("#vertical-strips ul li");
items.each(function(i){
    $(this).hover(
        function(){
            size = $(window).width()/items.length; 
            items.each(function(j){
                if(j != i ){
                    if($(this).width() > size - (40.0/items.length) + 5 ){
                        $(this).stop();
                        $(this).animate({width:size - (40.0/items.length)}, 10);
                    }
                }
            }); 
            $(this).stop();
            $(this).animate({width:size + 40}, 10); 
        },
        function(){
        }
    );
});

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

An error was encountered: The object 'object object' does not have the 'on' method available

I want to experiment with this website: However, I am encountering an error without any events triggering. I am confused why the method "on" is not being found even on page load. <head> <link href="css/scrollable-horizontal.css" rel="styleshe ...

What is the best way to use jQuery to increment the number in an input field by a specific value?

My goal is to utilize jQuery to increment a number in an input field and then display the updated value in the same input field. The specific id of this input field is "total". Here's my attempt so far: function addBag(){ var bagprice = 79.99; ...

Navigating Liferay Portlet in reverse order

I am facing an issue with right to left alignment in my portlet. It displays correctly when tested on a regular HTML page, but switches to left to right alignment when integrated into a Liferay portlet. Below is the code snippet causing this problem: < ...

An error has occurred with Datatables: dtSettings is not defined

I have successfully implemented data-tables with fixed columns on my project. The first data-table, patients_report, is working perfectly fine. However, the second one, visitation_report, is encountering some issues. Can someone please advise me on how t ...

Vertically center the container

I am struggling to center my container div vertically, similar to how it is horizontally aligning with margin: auto;. Despite searching online for solutions, I have not been successful in finding a method that works for me. It is surprising to me that in t ...

Having trouble with CSS box alignment issues in the top margin

I am working on customizing a CSS box for a navigation menu. Here is the current CSS code: .navigation-div { text-align:right; margin-top:14px; box-shadow:0px 0px 10px rgba(0,0,0,0.47); padding: 0; color:#E3E3E3; background-color: ...

The react transition group fails to add the necessary CSS classes to the specified div

Regardless of whether I utilize React transition group, Tailwind, pure CSS, or any other framework, no transitions seem to occur when I structure my simple component in the following manner. I have experimented with various frameworks, but the outcome rema ...

Stop ajax request when select2 is clicked

Is there a way to change the ajax call behavior in select2 drop down items so that it only retrieves data when I start typing in the search box, and not on click of the element? Your guidance on this issue would be highly appreciated. $("#ddlItems").sel ...

Clicking multiple times will impede the progress of AJAX requests

My webpage has multiple buttons that can be clicked very quickly, but it seems like Chrome is struggling to keep up with the speed? $(document).ready(function() { $('.favorite-button').unbind('click').click(function() { addLine ...

What steps can be taken to activate the remember password feature when using an AJAX login system?

I've developed a web application with a basic login box, utilizing jQuery AJAX for the login process. However, I'm facing an issue with prompting the browser to remember the password. How can I trigger the "Do you want the browser to remember th ...

Unable to access account: HTML Javascript login issue

Problem with Login Code As a newcomer to HTML, CSS, and almost unknown in Javascript, I sought help from others to create a login code. The code was working fine earlier, but now it's not functioning as expected. Despite checking everything, I can&ap ...

Is it possible to transmit an array using $.ajax and specify the dataType as json?

I am currently attempting to send a JavaScript array to my .php file handler and store it in my database. Although the request is successful, it seems like my array isn't being posted/saved correctly. When I check the POST request source, it shows up ...

How can I display a button (hyperlink) on a new line using CSS or jQuery?

I am looking to create a new line after the last input of my form. On this new line, I want to add a "remove-link". This is my HTML: <div class="subform dynamic-form"> <label for="id_delivery_set-0-price"> Price: </label> <inp ...

Creating a dual-direction infinite scroll effect with CSS through mouse dragging

I'm currently working on implementing an infinite scroll component for a project. After consulting this tutorial, I've encountered an issue. It seems that I can only achieve infinite scroll in one direction. Whenever I add elements to the leftmo ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

Interactive menu backdrop determined by div element

I am working on a website with a menu structured like the following: Home -- Work -- Pricing -- Contact Us -- About This website uses a one-page layout and has enabled Scrollspy on Bootstrap. I need to make the active menu background dynamic depending o ...

Sending a batch of items through an ajax request

I am faced with a challenge where I have a collection of data stored within multiple objects. Within each object, there is an ID and a status, while the main object contains a type and form id. The issue arises when trying to post the result via ajax as ...

What is the best way to adjust the fontSize of text within a table using Material UI?

In my Material UI table, I am attempting to adjust the fontSize of the contents. However, when I try to modify it using the style={{}} component, the changes are not being applied. <Grid><Typography variant="body1">Fiscal Year </Typography&g ...

Looking for a plugin that can color the text "Google" in the exact shade as the Google logo? Check out this jQuery

Is there a jQuery plugin or similar tool available that can change the color of each letter in the word "Google" to match the colors of the Google logo? For instance, if I have the following HTML markup: <span>Google AdWords</span> I would l ...

Apply a CSS class to the row that is not successful

I have implemented the Bootstrap Table in my project to load data remotely using data-url="data.json". Here is how I set up my table: <table id="mytable" class="table table-hover" data-url="data.json" data-toggle="table" id="table-pagination" data-pag ...