This project is archived and is in readonly mode.

#330 ✓wontfix
Thomas Allmer

Element.position enhancements

Reported by Thomas Allmer | July 22nd, 2010 @ 02:47 PM | in 1.3.1.1

as you can only return the position (option => returnPos: true) that would be set you can actually get the position of a completely different object and afterward only apply the position. [I love this feature]
So as this can be any different object it should be possible to ignore the adjustments from the OffsetParent and the scrolling as they may be something completely different.

I simply added 2 more options with an if statement
ignoreOffsetParent: false,
ignoreAllScroll: false

for details see commit
http://github.com/daKmoR/mootools-more/commit/b8fdee7bf63a462221615...

Comments and changes to this ticket

  • Arian

    Arian September 20th, 2010 @ 05:09 PM

    • Milestone set to 1.2.5.1
    • State changed from “new” to “open”
    • Assigned user set to “Aaron Newton”
    • Milestone order changed from “197504” to “0”
  • Aaron Newton

    Aaron Newton September 26th, 2010 @ 11:40 PM

    • Milestone order changed from “32” to “0”

    Thomas, can you elaborate as to why you'd want to ignore these things? What's the use case?

  • Aaron Newton

    Aaron Newton September 27th, 2010 @ 12:41 AM

    • Milestone changed from 1.2.5.1 to 1.3.1.1
    • Milestone order changed from “34” to “0”
  • Thomas Allmer

    Thomas Allmer September 27th, 2010 @ 02:14 AM

    hey Aaron here is my usecase.

    I want to get the centered position of a currently not visible element, without scrolling and offset. This position is then used to morph the size of a lightbox (completely different element), when switching images....

    pls go to the following page and open the first image (top left)

    http://demo.webteam.at/galerie/detail-lightbox/

    now if you do a
    $$('.ui-ItemItem')[2].position({returnPos: true}); // {left: -10, top: -10}

    you get the "relative" position of the element (with it offsets, scrolling), but what I want the "absolute" position from the window, as I will apply the position to a completely different element

    if you use the two options I described above you get the positions I actually want...
    $$('.ui-ItemItem')[2].position({returnPos: true, ignoreOffsetParent: true, ignoreAllScroll: true}); //{left: 437, top: 150}

    I also created a simplified use case as jsfiddle
    http://jsfiddle.net/cqzEk/

    and yeah using the already available ignore settings is not enough
    http://jsfiddle.net/cqzEk/1/

    conclusion: if you just get the position and want to apply it a completely different element it's important to be able to ignore all Offset and Scroll...

    I hope this makes it clearer, if you have any further questions just let me know...

  • JacobThornton

    JacobThornton December 5th, 2010 @ 07:20 AM

    • Milestone order changed from “8” to “0”

    I'm not totally sure i follow you, but i think you just want to get the position of your images relative to the window (rather than a scrolled body) -- if that's the case, rather than adding those options to -more -- you could instead just set the position of the element whose position you are trying to calculate to "fixed" before you call position on it like this (http://jsfiddle.net/jacob/cqzEk/21/) ... that will give you it's size relative to the window, and allow you set the position of your lightbox's container accordingly. (you can of course afterward toggle to the position to relative, etc.)

    if this is the case could you please tell us? Or if not, help me understand better -- thanks :)

  • JacobThornton

    JacobThornton December 28th, 2010 @ 07:01 AM

    • State changed from “open” to “wontfix”

    @thomas -- i'm marking this ticket as wontfix. The reason being that OffsetParent won't always give you the window object (like you want) so adding an option to ignore it doesn't make sense -- in fact often you might want several nested divs which are positioned relatively (which means mutiple offsets). Ultimately the problem here is an api problem.

    So what can you do instead?

    The easiest is the positioned fixed trick i posted above (which having looked at your code should work really great for you, with minimal code changes) -- however, the better way (IMHO) is to use a combination of getPosition/getScroll to calculate the correct position yourself (which is practically only a few lines of code :) and really the cleaner solution.

    Either way, hope that helps and thanks for reporting. Also, please let us know if I've misunderstood you or if you have anything else you'd like to bring up.

Create your profile

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

The MooTools Extensions

Pages