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 8132249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:18:06+00:00 2026-06-06T09:18:06+00:00

I have a question regarding animations via javascript in HTML using DOM. In this

  • 0

I have a question regarding animations via javascript in HTML using DOM. In this case I am using a with absolute possition and css + jQuery and animate the div.

So when I run through my big array of positions x,y the animation runs very slow. I am running at 100ms (80ms) Interval, but it seems that the rendering is not fast enough and my animations takes longer than 10 seconds…

When re-running the animation it seems that the instructions have been somehow cached ( Rendering ) and my animations runs just perfect.

Then again if I wait for lets say 5 mins, it will be slow again. ( Seems to be low level machine code memory which has been deleted, because it was not used again? )

I just cant figure out how to let my animation run smooth, if its executed the first time.
I tried fabric.js to render animations… Same problem. At the first run its slow. Second run and following are smooth.

function render_mouse()
 {
     if(play_pos < mousefile_length)
         {
            $('.mouse').remove();
            $("body").append(
            $('<div id="mouse" class="mouse"></div>')
            .css('position', 'absolute')
            .css('top', play_mousefile[play_pos+1] + 'px')
            .css('left', play_mousefile[play_pos] + 'px')
            .css('width', mousesize)
            .css('height', mousesize)
            .css('background-image', 'url(images/cursor.png')
                    );
            play_pos = play_pos +2;
            }
    else {
        clearInterval(play_mousetimer);
         }
   }

UPDATED:
 $('#mouse').animate({
                 left: rec_mousefile[play_pos]+"px",
                 top : rec_mousefile[play_pos+1]+"px"
                 },80);
  • 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-06-06T09:18:08+00:00Added an answer on June 6, 2026 at 9:18 am

    The animation would be faster if you didn’t do so many operations on the mouse div every time.

    Basically, append the mouse to the dom once, with all the CSS needed for the initial render, cache the reference to the appended element, and then manipulate ONLY the css properties necessary for the animation.

    By keeping the element in the dom, rather than removing and re-appending each time, you should see a bit of a performance increase. Further, saving a reference to the appended element will prevent you from having to re-query the dom before giving another update.

    The animation should always be a bit faster on a second run due to caching, but these optimizations should help the initial run at least a bit.

    ** edit in response to comment **

    You could cache the reference to the mouse div outside the function, or hang it off the render function itself, a la:

    var mouseDiv = $(‘#mouse’);

    function render_mouse()
    {
        if(mousefile_length > play_pos)
                    {
                     mouseDiv.animate({
                     left: rec_mousefile[play_pos]+"px",
                     top : rec_mousefile[play_pos+1]+"px"
                     },80);
    
                     play_pos=play_pos+2;
            }
       else {playtimer.stop();}
    }
    

    or

    function render_mouse()
    {
        // query the first time, and then use the cached version thereafter
        render_mouse.mouse = render_mouse.mouse || $('#mouse');
        if(mousefile_length > play_pos)
                    {
                     render_mouse.mouse.animate({
                     left: rec_mousefile[play_pos]+"px",
                     top : rec_mousefile[play_pos+1]+"px"
                     },80);
    
                     play_pos=play_pos+2;
            }
       else {playtimer.stop();}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding the onkeypress event on JavaScript. Is it possible to
I have a question regarding the integration of business objects developed using Linq To
I have a question regarding the method i am using for doing Business Rule
I have question regarding shared memory segmentation in c using POSIX system calls. Is
I have a question regarding jQuery. I have multiple images that are, in essence,
I have question regarding polymorphism about its assignment statement, for Example this is The
I have a question regarding django templates and html frameset's. I would like to
I have a question regarding calling methods from different threads. Well I am using
I have question regarding about finding subview using '.tags' in one UIView. for (UIView
I have a question regarding finding characters (numbers in my case) in the middle

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.