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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:09:38+00:00 2026-06-14T07:09:38+00:00

i try to absolutize previously relative DOM element, and everytime i try it, a

  • 0

i try to “absolutize” previously relative DOM element, and everytime i try it, a strang “jump” occures, and i just don’t know what i’m doing wrong or how to solve this.

ok, the JS_fidle can be found here http://jsfiddle.net/rhqy3/3/

this is the dummy HTML

<html>
<body>
    <br><br><h1>one</h1><br><br><br><br>
    <h2>two</h2>
</body>
</html>​

this is the javascript (using jquery)

jQuery.fn.absolutize = function()
{
  return this.each(function()
  {
    var element = jQuery(this);
    if (element.css('position') == 'absolute')
    {
      return element;
    }
    alert('now a jump happens, that should not happen')
    element.css("position", "absolute");
    element.css(element.offset());
    return element;

  });
}


$(document).ready(function() {
            window.setTimeout(function(){$("h1, h2").absolutize()}, 2000)
        });

​
ok, well, after two seconds, when i want to set the elements to their absolute equivalents, there is a …. jump?!? and i don’t know why. i tried $(element).position() instead of offset(), didn’t work out.

update: clarification – the h1 stays where it is, the h2 makes the jump. i tested in to google chrome latest, firefox latest on mac os x lion.

my goal is to set elements (vie the absolutize jquery plugin) to their real (not jumping) equivalent css-absolute position, how to do it? thx, i really appreciate it, thx for your time.

update 2: heureka, i’ve identified the problem (still missing the solution)! the problem: the DOM is too fast. what does this script do: it gets the h1-element, says: take this out of the relative context (the normal rendering flow) and set it to “absolute”, in this moment a browser reflow happens – as the H1 is no longer there, everything moves up. the jump occurs. this is so fast that we don’t see it. now the jquery function goes to the h2 and says “absolute” but in this moment the h2-element has already the “new” relative positioning, the jump did already happen. that’s the reason not everybody sees it, it’s a racing condition. if the browser is to slow triggering the reflow, the DOM still holds the old values. ok
,what to do: we have to collect the postion values of all elements (save them somewhere), then, after all postion values were collected, we update one element after the other. not quite sure how to do this in the context of a jquery plugin, but i will get to it (tonight, now back to work).

update 3: the answer below it the right answer to this issue. thx a lot. one thing that this doesn’t solve (because i didn’t ask for it) is the issue that the other elements, that might depend on the relative positioned elements then do some reflow dance (as the suddenly absolutized elements went missing), this little jquery plugin solves this https://gist.github.com/4051578, it’s a jquery plugin called jquery.bodysnatch.js as it’s purpose is “jquery plugin that replaces elements with absolute positioned clones of themselves, while hiding & silencing the originals” have fun.

  • 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-14T07:09:39+00:00Added an answer on June 14, 2026 at 7:09 am

    Here you go!

    http://jsfiddle.net/rhqy3/9/

        (function($){
            $.fn.absolutize = function() {
                var elems = [];
                this.each(function() {
                    var element = $(this);
    
                    if (element.css('position') == 'absolute') return;
    
                    var offset = element.offset();
                    elems.push({
                        el: element,
                        newRules: {
                            position: 'absolute',
                            top: offset.top,
                            left: offset.left
                        }
                    });
                });
    
                $.each(elems, function(i, obj){
                    obj.el.css( obj.newRules );
                });
            };
    
            $(document).ready(function() {
                window.setTimeout(function(){
                    $("h1, h2").absolutize()
                }, 2000);
            });
    
        })(jQuery);​
    

    The problem was, it was going through each element passed in to absolutize() one at a time, taking the offset, and applying it. By the time the it was asking for the offset of the h2, the h1 had already been removed from the flow of the document.

    There may be a better way to code this, but the idea is, cache the elements’ offsets before changing each of their positions.

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

Sidebar

Related Questions

When I try to use position: relative / position: absolute on a <th> or
I try to get size of GWT element with CssClass using standard methods, but
Okay, I know this has been asked before, but the solutions to previously asked
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i);
try { $friends = $facebook->api('/me/friends'); } catch (FacebookApiException $e) { error_log($e); } Shows :Fatal

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.