Ticket #8425 (closed bug: notabug)
UI Position doesn't handle fixed elements correctly
| Reported by: | Jens Roland | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.9.0 |
| Component: | ui.position | Version: | 1.8.21 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
The Position utility script doesn't account for the target element being fixed to the viewport (position:fixed).
The source element (the one we are trying to position next to the target, e.g. a tooltip) needs to become fixed if the target is, in order to stay adjacent to it if the user subsequently scrolls down the page.
Demo: http://jsfiddle.net/3CBRa/9/
Proposed fix: On line 213, add:
if (target.css('position')=='fixed') elem.css('position','fixed');
Demo with implemented fix: http://jsfiddle.net/gJpNT/1/
I will submit a pull request right away.
Change History
comment:2 Changed 12 months ago by scott.gonzalez
- Status changed from new to closed
- Resolution set to invalid
This is not a bug. The position utility is purely for setting the position, not the type of positioning that the element uses. If you want the element to follow it, that's a separate decision from deciding that at a specific time two elements should be aligned in a specific way.
comment:3 Changed 12 months ago by Jens Roland
That may be the goal of the utility, but it is never the desired behavior in any application.
comment:4 Changed 12 months ago by scott.gonzalez
That's actually not true. Besides, what you want is not solved by just setting position. What happens if the target element is repositioned later? What happens if the target element isn't fixed, but is contained in a scrollable parent? What happens if the element being positioned is contained in a scrollable parent? All of these cases are completely out of scope for this plugin.


Issue reproduced and fix verified in:
Both on Windows7 64bit
Pull request #688: https://github.com/jquery/jquery-ui/pull/688