Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:21:12+00:00 2026-05-26T18:21:12+00:00

Why oh why is this so slow? I have made an isometric grid of

  • 0

Why oh why is this so slow? I have made an isometric grid of cubes with css3 that bobs up and down on mouseover. It works great on Firefox with a grid size less than about 12 and with Chrome works pretty good under about 18. I have a decent video card and CPU and the thing that is bugging me is why it is so slow to animate just one cube’s animations if I make sure I only mouseover one cube. Does my JavaScript need optimisation or is this just to be expected from the current implementation of browser CSS3 and JavaScript engines? Full test case below includes slider to change grid size on the fly, can either download for yourself or visit this jsfiddle version graciously provided by Doug.

<html>
    <head>
        <style type="text/css">
            body
            {
                background: black;
            }

            .cube
            {
                position: relative;
            }

            .cube .rightFace, .cube .leftFace
            {
                height: 25px; width: 10px; padding: 5px;
            }

            .leftFace
            {
                position: absolute;

                -webkit-transform: skew(0deg, 30deg);
                -moz-transform: skew(0deg, 30deg);
                -o-transform: skew(0deg, 30deg);

                -moz-box-shadow: rgba(0, 0, 0, 0.4) 1px 2px 10px;
                -webkit-box-shadow: rgba(0, 0, 0, 0.4) 1px 2px 10px;
                -o-box-shadow: rgba(0, 0, 0, 0.4) 1px 2px 10px;
                box-shadow: rgba(0, 0, 0, 0.4) 1px 2px 10px;

                border: 1px solid black;
            }

            .rightFace
            {
                -webkit-transform: skew(0deg, -30deg);
                -moz-transform: skew(0deg, -30deg);
                -o-transform: skew(0deg, -30deg);

                position: absolute;
                left: 19.5px;

                border: 1px solid black;
            }

            .topFace div
            {    
                width: 19px;
                height: 19px;


                border: 1px solid black;

                -webkit-transform: skew(0deg, -30deg) scale(1, 1.16);
                -moz-transform: skew(0deg, -30deg) scale(1, 1.16);
                -o-transform: skew(0deg, -30deg) scale(1, 1.16);
            }

            .topFace
            {
                position: absolute;

                left: 10.25px;
                top: -16.5px;

                -webkit-transform: rotate(60deg);
                -moz-transform: rotate(60deg);
                -o-transform: rotate(60deg);
            }

            #slider
            {
                width: 200px;
                margin: 0 auto;
            }
        </style>
        <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
        <script type="text/javascript">
            function refreshCubes()
            {
                $('.box').empty();
                var x = $("#slider").slider("value");
                var initialTop = 50;
                var initialLeft = 450;

                for(var i = 1; i < x; i++)
                {
                    for(var j = 1; j < x; j++)
                    {
                        var cube = $('<div class="cube"><div class="topFace"><div></div></div><div class="leftFace"></div><div class="rightFace"></div></div>');

                        cube.css(
                        {
                            left : initialLeft + (20 * i) + (-19 * j) + 'px',
                            top : initialTop + (11 * i) + (11 * j) + 'px'
                        });

                        cube.find('.topFace div').css('background', 'rgb(100,' + Math.ceil(255 - 16 * i) + ',' + Math.ceil(255 - 16 * j) + ')');
                        cube.find('.rightFace').css('background', 'rgb(35,' + Math.ceil(190 - 16 * i) + ',' + Math.ceil(190 - 16 * j) + ')');
                        cube.find('.leftFace').css('background', 'rgb(35,' + Math.ceil(190 - 16 * i) + ',' + Math.ceil(190 - 16 * j) + ')');
                        cube.children('div').css('opacity', '.9');

                        cube.hover(function()
                        {
                            $(this).animate({top: '-=25px'}, 400, 'easeInCubic');

                        }, function()
                        {
                            $(this).animate({top: '+=25px'}, 400, 'easeOutBounce');
                        });

                        $('.box').append(cube);
                    }
                }
            }

            $(document).ready(function()
            {    
                $('#slider').slider(
                {
                    value: 9,
                    max: 30,
                    min: 2,
                    slide: refreshCubes,
                    change: refreshCubes
                });

                refreshCubes();
            });
        </script>
    </head>
    <body>
        <div id="slider"></div>
        <div class="box"></div>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:21:13+00:00Added an answer on May 26, 2026 at 6:21 pm

    This one is faster: http://jsfiddle.net/JycdN/1/

    I optimized the jQuery code itself. Also, its a bad idea to animate a “+=25px” style CSS value because each time you do that you are forcing the browser to make extra CSS calculations on top of the animation calculations. Instead of doing that, you might as well just use plain CSS3 animations. Check this out: http://matthewlein.com/ceaser/

    Its better for animate() to have a static value (in this case, the original and raised positions which i’ve stored for each cube in the data- attributes) so the only calculations being done are the ones by the javascript interpreter itself.

    The live() method automatically adds the events to the cubes whenever they are recreated, so there’s no need to set the events inside the refreshcubes function. Also, James Montagne pointed out that using the live() method makes the whole thing behave like Daniel described in his answer (which is faster).
    EDIT: I’ve made it even faster by using the on() method instead of live(). The event context for hovering is now on each cube instead of on the whole document. See this question for details: How does jQuery's new on() method compare to the live() method in performance?.

    Wherever possible, make one single jquery object and reference to it with a variable, that way you don’t recreate a new object every time.

    Overall, I noticed quite an increase in performance, but its still slower than I’d imagine capable. Maybe the CSS transforms are re-calculated every time the cubes are moved (even by a pixel).

    EDIT: As addedlovely suggested, modifying the jQuery.fx.interval helped make it a little faster.

    I think you’ll have more luck drawing the cubes in 2D canvas or with 3D webGL canvas.

    Try using three.js or processing.js to draw the cubes and animate them.

    EDIT: I’ve made it even faster using hardware-accelerated CSS3 animations in Google Chrome (other browsers are still developing these CSS3 features so it only works in CHrome for now): http://jsfiddle.net/trusktr/JycdN/35/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
Suppose I have this: $('ul.child').slideUp('slow'); What would be the regex to find 'ul.child' and
I have the following jQuery: $(#toolbar).hover(function () { $(.logo).fadeOut(slow, function () { $(this).addClass(logohover) $(this).parent().addClass(logohover).fadeIn(slow,
I'm using Log4Net to write logs to files. Can this serioulsy slow down my
This is somewhat of a sequel to Slow Exists Check . Alex's suggestion works
Is this true that Update SQL Query is slow because of Clustered index??????
This method that draws my tiles seems to be quite slow, Im not sure
actually this is not hang status, i mean..it slow response, so in that case,
I have made a player that plays mp3 and does the job very well
I'm having hard time getting this snippet to work. I have made a minimal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.