Why is my jQuery animation running so sluggishly everywhere? Is there a way to improve its performance and make

I attempted to replicate the slider effect seen on this website:

Below is the animation code:

$('.tagLink').click(function () {
            $('html').css('overflow', 'hidden');
            $('#tagBoxOverlay').show().stop(1).fadeTo(200, .9)
            $('#tagBox').show().stop(1).animate({
                marginTop: '-37.5%',
                marginLeft: '-37.5%',
                height: '75%',
                width: '75%',
                opacity: 1
            }, {
                duration: 200,
                specialEasing: {
                    opacity: 'linear',
                    width: 'linear',
                    height: 'linear',
                    marginLeft: 'linear',
                    marginTop: 'linear'
                },
                complete: function () {
                    $(tagBoxContents).fadeTo(200, 1);
                    $('#tagBoxPopularWrapper').height($('#tagBox').height() - $('#tagBoxDescription').height() - 1);
                    $(window).resize(function () {
                        $('#tagBoxPopularWrapper').height($('#tagBox').height() - $('#tagBoxDescription').height() - 1)
                    });
                }
            });

tagBoxOverflow and tagBox initially have 100% width & height. The overlay fades in, and the box both fades in and reduces in size.

You can view this effect in action on this website: Click "begin," then click "hipsters," and the animation will occur.

Why is the animation so slow? Here's the direct link to the JS file:

I am confused and struggling to figure this out. I am aware that this might be demanding on the browser, but Metalabs seems to handle it smoothly! Could it be better if I used CSS animations with JS as a backup?

Answer №1

Using CSS3 transitions is definitely a smoother experience (although Internet Explorer doesn't always cooperate).

One major issue I see is with your margins.

I recommend setting it to position: absolute and animating the top, right, bottom, and left properties.

By doing this, the browser won't have to reflow the entire page every time, as resizing won't affect the containing element or any of its parent elements.

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

Tips for sharing data between two components

In my project, I have a customized Shared Component which consists of an input search bar with a "continue" button. This Shared Component is being utilized within two other components - the buy component and sell component. The challenge I am encountering ...

Can child elements be centered using their pseudo-elements using CSS alone?

Consider the code snippet below: <div class="example-container"> <p class="example">a</p> <p class="example">bbb</p> <p class="example">cc</p> </div> and the cor ...

Utilizing JavaScript to Parse RSS XML Feeds Across Domains

Looking to parse an RSS (XML) file without relying on the Google RSS feed. I have attempted using JSONP, but it resulted in downloading the file and throwing an error "Uncaught SyntaxError: Unexpected token < ". $.ajax({ type: "GET", ur ...

Updating the Animation for Datepicker Closure

While using the date picker, I want it to match the width of the input text box. When closing the date picker, I prefer a smooth and single motion. However, after selecting a from and to date, the datepicker no longer closes smoothly. I have attempted sol ...

What is the best method for adding a header to a dynamically created table using JavaScript?

After receiving JSON data in my JavaScript, I have successfully converted it into an HTML table. Everything seems to be working fine, but I'm wondering how I can add a header to my table? Below is the code snippet: <script> $(document ...

My website has a navbar button that is not directing to the intended section of the screen

I have created this HTML code for my Navbar buttons: <button class="navbar-toggle" data-toggle = "collapse" data-target=".navHeaderCollapse"> <span class="icon-bar"></span> <span class="icon-bar">< ...

Show and hide a div with the click of a button

As I embark on rebuilding a website from the ground up, I find myself pondering how to achieve a specific functionality: My goal is for another view to appear when one of two buttons is clicked. How can this be accomplished? I attempted the following app ...

JavaScript Linked List Operations: Issues with the removeHead() and contains() Functions

Incorporating ES6 syntax, the challenge is to construct a linked list and subject it to an npm linter test. Below is the code implementation: class LinkedList { constructor() { this.head = null; this.tail = null; // Do not alter anything wit ...

Steer clear of cross-domain solutions

Currently, I am developing a web application that allows customers to integrate it into their websites by linking to a JavaScript file on my server. Despite the application reading all JavaScript files from my server, I encounter an error when attempting t ...

Querying MongoDB in Loopback is posing a challenge

My attempt to query MongoDB from a LoopBack model is not yielding any results. This is an example of how my document appears in MongoDB: {"_id":"5b9f8bc51fbd7f248cabe742", "agentType":"Online-Shopping", "projectId":"modroid-server", "labels":["category", ...

Creating a web form with the ability to select multiple images using Javascript

Currently, I am in the process of developing an HTML form that enables users to select an image, a URL, and text that will be inserted as a <li> into a webpage. However, I am facing an issue where I want users to create multiple <li> per input. ...

I'm noticing that my Tailwind styles don't take effect until I redefine them. What could be causing

My Tailwind classes are giving me trouble. I faced an issue when I created a new component in the directory and placed my Button component there. Whenever I restart the project in terminal, the styles do not apply to my button unless I manually define th ...

Ensuring the height of the HTML element for menu items matches the navigation bar

I've been struggling to customize a navigation bar styled with Bootstrap 4. My goal is to create a hover effect on the menu items similar to the image or code snippet provided, but without that annoying thin blue flashing offset below the item. Despit ...

Struggling to modify a nested object in the state

import React, { Component } from 'react'; import ColorBox from './ColorBox' import './ColorBoxes.css' class ColorBoxes extends Component { state = { colors: {} } clickedColor = (color) => { le ...

Creating a dynamic image carousel using jQuery

Today, I completed the jQuery course on Code Academy and am now trying to create an image slider using it. While I have a general idea of how it should work, I feel like I'm missing a key element. My goal is to have the slider continuously running whe ...

Manipulating arrays of objects using JavaScript

I am working with an array of objects represented as follows. data: [ {col: ['amb', 1, 2],} , {col: ['bfg', 3, 4], },] My goal is to transform this data into an array of arrays like the one shown below. [ [{a: 'amb',b: [1], c ...

In what ways can the accessibility of a website be impacted by using CSS

After reading numerous articles on Google and Stack Overflow, I have decided to ask my question straightforwardly in the hopes of receiving a clear and direct answer. Adding another layer to the discussion about whether Does opacity:0 have exactly the sam ...

Mobile device scrolling glitch

I'm currently working on my website, which can be found at . After testing it on mobile devices, I came across an issue that I just can't seem to fix. For instance, when viewing the site on a device with 768px width, you can scroll to the righ ...

Is it possible to link to a .json file stored on my server and then create a template for it?

I have set up a Webserver on kasserver.com, and I have a PHP script that retrieves data from an API every 15 minutes and saves it on my Webserver. Now, I am looking to create a template for the saved JSON data, but I am having trouble accessing it locally. ...

Bringing PHP Back into the World of Ajax

I created a form for users to upload new avatars and now I am experimenting with using AJAX to display error messages on the same page if any occur. However, my current issue is that the AJAX call is not receiving any response from the PHP file it's c ...