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

  • SEARCH
  • Home
  • 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 8063153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:55:40+00:00 2026-06-05T10:55:40+00:00

My code is here . There are three position: zero(0,0) , end(200,200) , random(0,200)

  • 0

My code is here.
There are three position:zero(0,0),end(200,200),random(0,200).

A div is in the position random(0,200) at the beginning.

I want to :

step 1) set the div in the position zero(0,0). this step no animation

step 2) move it from position zero to position end by transition. this step has animation

Code like this does’t work very well:

document.getElementById('x').className = 'pos_zero';    // set the div to the position zero(0,0)
move(); 
// in function move: 
// document.getElementById('x').className = ' trans'; 
// document.getElementById('x').className += ' pos_end' ;

It seems that transition starts too early, while css style(className = 'pos_zero') hasn’t applied completely yet. It just directly moves from position random to position end. And what I really want is the animation to position end from position zero, not from random.

Code like this works:

document.getElementById('x').className = 'pos_zero';    // set the div to the position zero(0,0)    
setTimeout('move()',1);

This code do successfully by using a timeout function. This code sets the div in the position pos_zero first and then do transition asynchronously by a timeout function. And the timeout function seems not very professional.

So, I’m looking for a more professional solution.

By the way. I wonder. If there is any way to ensure the style is applied completely, like “Style.flush()” or something?

@Inerdial It does work!Many thanks.To force an update (to force an immediate, synchronous reflow or relayout), your javascript should read a property that’s affected by the change, e.g. the location of someSpan and otherSpan.` The new code works without Timeout.

document.getElementById('x').className = 'pos_zero';
var tmp = document.getElementById('x').offsetTop; // read a property to force an update.
move(); 

Thank you guys all. And sorry for the confusing made by me.

  • 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-05T10:55:42+00:00Added an answer on June 5, 2026 at 10:55 am

    Thanks to @Inerdial. It does work!.
    Actually this answer is coming from his comment.

    To force an update (to force an immediate, synchronous reflow or relayout), your javascript should read a property that’s affected by the change, e.g. the location of someSpan and otherSpan.` – stackoverflow.com/a/1397505/41655

    The new code works without Timeout(jsfiddle.net/vd6V8):

    document.getElementById('x').className = 'pos_zero';
    var tmp = document.getElementById('x').offsetTop; // read a property to force an update.
    move(); 
    

    Thank you guys all. And sorry for the confusing made by me.

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

Sidebar

Related Questions

There are some questions on Code Metrics here, especially this one on goal values.
here is the code: http://jsfiddle.net/duNHJ/2/ Basically there is an animations every div so when
Is there any way to make this code shorter? price1 = input(\nEnter price here:
There are a lot of posts on here about this, I'm using this code
There is a weird code here that I need to make work.. can you
i'm trying wmd editor over ajax. here there is the bugged code wdm code
there is ANR problem comes when we click gridView Item.My code is here.. @Override
here ,i am using wpf .in my code there is one folder named by
Here's my code, I know there's a small mistake somewhere but being a noob
Is there a way to execute internal code via reflection? Here is an example

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.