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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:53:45+00:00 2026-05-27T19:53:45+00:00

Ok, got a weird bug going on here and so far google has failed

  • 0

Ok, got a weird bug going on here and so far google has failed to turn up anything addressing it.

When using IE7 (actually IE8 compatibility) the JQuery offset function is not returning the current offset of an element. Here is a really quick test page to demo the issue:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script>

    <style type="text/css">
        div#Content
        {
            height: 400px;
            overflow: auto;
            border: solid 1px black;
            padding: 2px;
        }
        div.Spacer
        {
            height: 300px;
            border: dotted 1px black;
            background: #ddd;
        }
        div.Wrapper
        {
            padding: 5px;
        }
        div#MoveMe
        {
            position: absolute;
            z-index: 5;
            display: none;
            background-color: Blue;
        }
    </style>
</head>
<body>

    <script type="text/javascript">
        function SetPosition() {
            var divContent = $("div#Content");
            var divMoveMe = $("div#MoveMe");
            var Textbox = $("input#textbox");

            var divMoveMeOffset1 = divMoveMe.offset();

            divMoveMe.css({ "top": "0px", "left": "0px" });
            divMoveMe.height(0);
            divMoveMe.width(0);

            var divMoveMeOffset = divMoveMe.offset();
            var TextboxOffset = Textbox.offset();
            var ContentScrollTop = divContent.scrollTop();
            var ContentScrollLeft = divContent.scrollLeft();
            var divLeft = ((TextboxOffset.left - divMoveMeOffset.left)) + Textbox.outerWidth();
            var divTop = (TextboxOffset.top - divMoveMeOffset.top);
            divMoveMe.css({ "top": divTop + "px", "left": divLeft + "px" });
            divMoveMe.height(Textbox.outerHeight());
            divMoveMe.width(Textbox.outerWidth());

            var divMoveMeOffset2 = divMoveMe.offset();
        }

        $(document).ready(function() {
            $("div#MoveMe").show();
            SetPosition();
            $("div#Content").scroll(SetPosition);
            $(window).scroll(SetPosition);
            $(window).resize(SetPosition);
        });
    </script>

    <div id="Content">
        <div id="Spacer1" class="Spacer">
        </div>
        <div class="Wrapper">
            <input id="textbox" />
            <div id="MoveMe">
            </div>
        </div>
        <div id="Spacer2" class="Spacer">
        </div>
    </div>
    <div id="Spacer3" class="Spacer">
    </div>
</body>
</html>

In IE 8 and firefox the blue div is correctly positioned adjacent to the textbox, and holds this relative position through scrolling etc. However when I kick back to IE7 it is not holding position correctly.

As near as I can tell the offset function is always returning the position values for the div at the time the SetPosition function was called, they do not see the changes that should result from setting the top and left css properties. I have verified this by adding a couple of extra calls to the offset method and putting a watch on the three results. All three report the same offset numbers even though top and left are changed between the calls.
Does anyone know a way to make offset update after changing the css properties? Or an alternate approach?

I should note that this is going into a web control, none of the markup, or related styles, outside of the Wrapper div can be modified for a valid solution, in fact I need to be able to modify them without breaking this behavior.

UPDATE: in playing with this a bit more I noticed that the issue only seems to occur when the function is called during the scroll event, the call during document ready works correctly.

  • 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-27T19:53:46+00:00Added an answer on May 27, 2026 at 7:53 pm

    Ok, I figgured out what was happening, if not exactly why, and I was able to come up with a work around.

    In IE 7, if my method is called from the content div’s scroll event, then the jquery position and offset methods will always return the same values within the context of the event. Even though the element is repositioned multiple times, these methods appear to return the values for the position it held at the start of the event. If the method is called by other means, such as the document ready event, then everything seems to work correctly and the position calculations are sensitive to the changing position of the element. I should also note that falling back and calculating the position using standard javascript has the same behavior.

    The workaround I came up with was to split my positioning method into two parts, the first part zeros out the position of my div and the second part sets the new position. I then use setTimeout in the first method to call on the second method. This breaks me out of the event context so that my position calculations are correctly able to find the zero point of the div.

    var t;
    function SetPosition() {
        var divMoveMe = $("div#MoveMe");
        if (t) {
            clearTimeout(t);
        }
    
        divMoveMe.css({ "top": "0px", "left": "0px" });
        divMoveMe.height(0);
        divMoveMe.width(0);
    
        t = setTimeout(function() { SetPosition2(); }, 0);
    }
    function SetPosition2() {
        var divMoveMe = $("div#MoveMe");
        var Textbox = $("input#textbox");
    
        var divMoveMeOffset = divMoveMe.offset();
        var TextboxOffset = Textbox.offset();
        var divLeft = ((TextboxOffset.left - divMoveMeOffset.left)) + Textbox.outerWidth();
        var divTop = (TextboxOffset.top - divMoveMeOffset.top);
        divMoveMe.css({ "top": divTop + "px", "left": divLeft + "px" });
        divMoveMe.height(Textbox.outerHeight());
        divMoveMe.width(Textbox.outerWidth());
    }
    

    EDIT: This version of the code works correctly as well. It appears that the key thing is to break out of the event context before performing the position calculations.

    var t;
    function SetPosition() {
        if (t) {
            clearTimeout(t);
        }
        t = setTimeout(function() { SetPosition2(); }, 0);
    }
    function SetPosition2() {
        var divContent = $("div#Content");
        var divMoveMe = $("div#MoveMe");
        var Textbox = $("input#textbox");
    
        divMoveMe.css({ "top": "0px", "left": "0px" });
        divMoveMe.height(0);
        divMoveMe.width(0);
    
        var divMoveMeOffset = divMoveMe.offset();
        var TextboxOffset = Textbox.offset();
        var divLeft = ((TextboxOffset.left - divMoveMeOffset.left)) + Textbox.outerWidth();
        var divTop = (TextboxOffset.top - divMoveMeOffset.top);
        divMoveMe.css({ "top": divTop + "px", "left": divLeft + "px" });
        divMoveMe.height(Textbox.outerHeight());
        divMoveMe.width(Textbox.outerWidth());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've got something really weird going on here, and can't quite put my
I've got a weird bug occurring in a compact database on a Vista deployment
I've got a really weird problem and i'm wondering if it's a visual's bug
I got a weird bug. In my .css file I have the following rule:
I am using mongo db and I got one weird problem when calling to_json
Got a weird bug best shown by this page http://www.zoecormier.com/freelance/ Scroll down to the
I have got this super weird bug in my current project. To understand what
I've got this weird bug happening. I'm basically just adding a few minutes to
I've got a weird little bug which is occurring under MvvmLight v4 (.NET 4
I've got a bug caused by some weird behavior. I might be fundamentally missing

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.