#1231 new

Element.positionedOffset() subtracts margin-left from top, margin-top from left

Reported by roengraft | March 30th, 2011 @ 09:24 PM

In the latest prototype 1.7, positionedOffset was rewritten to rely on the new Element.Layout object. Margin left is supposed to be subtracted from the left attribute returned, but margin-top is used instead, and vice-versa. The offending lines of code in layout.js:


    valueL -= layout.get('margin-top');
    valueT -= layout.get('margin-left');

The fix is simply swapping the right hand sides of these two lines.

A simple test case to reproduce the problem I was having:

<!DOCTYPE html>
    <meta charset="UTF-8" />
    <script type='text/javascript' src="prototype.js"></script>
    <div id='wrap' style='position: relative;'>
        <div id='test' style='margin-left: 5px; position: absolute; top: 50px; left: 10px;'></div>
    <script type='text/javascript'>
        var start = function() {
            offset = $("test").positionedOffset();
            // should be 10, 50, but is 10, 45 with current version
            alert("left: "+offset.left+" top: "+offset.top); 
        document.observe("dom:loaded", start);

The above is similar to how I discovered this -- margin left without a margin top, then reading 'top' from either positionedOffset() or layout.get('top') (which just uses positionedOffset ...)

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Referenced by