.position( options )Returns: jQueryversion added: 1.8
Description: Position an element relative to another.
-
.position( options )
-
optionsType: Object
-
my (default:
"center"
)Type: StringDefines which position on the element being positioned to align with the target element: "horizontal vertical" alignment. A single value such as"right"
will be normalized to"right center"
,"top"
will be normalized to"center top"
(following CSS convention). Acceptable horizontal values:"left"
,"center"
,"right"
. Acceptable vertical values:"top"
,"center"
,"bottom"
. Example:"left top"
or"center center"
. -
at (default:
"center"
)Type: StringDefines which position on the target element to align the positioned element against: "horizontal vertical" alignment. See themy
option for full details on possible values. -
of (default:
null
)Which element to position against. If you provide a selector or jQuery object, the first matching element will be used. If you provide an event object, thepageX
andpageY
properties will be used. Example:"#top-menu"
-
offset (default:
null
)Type:Distance in pixels to adjust the position of the element horizontally and vertically, e.g."10 50"
. A single value such as"50"
will apply to both directions. -
collision (default:
"flip"
)Type: StringWhen the positioned element overflows the window in some direction, move it to an alternative position. Similar to
my
andat
, this accepts a single value or a pair for horizontal/vertical, e.g.,"flip"
,"fit"
,"fit flip"
,"fit none"
.-
"flip"
: Flips the element to the opposite side of the target and the collision detection is run again to see if it will fit. Whichever side allows more of the element to be visible will be used. -
"fit"
: Shift the element away from the edge of the window. -
"none"
: Does not apply any collision detection.
-
-
using (default:
null
)Type: Function()When specified, the actual property setting is delegated to this callback. Receives a hash oftop
andleft
values for the position that should be set and can be forwarded to.position()
or.animate()
.
-
-
The jQuery UI .position()
method allows you to position an element relative to the window, document, another element, or the cursor/mouse, without worrying about offset parents.
Note: jQuery UI does not support positioning hidden elements.
This is a standalone jQuery plugin and has no dependencies on other jQuery UI components.
This plugin extends jQuery's built-in .position()
method. If jQuery UI is not loaded, calling the .position()
method may not fail directly, as the method still exists. However, the expected behavior will not occur.
Example:
A simple jQuery UI Position example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
|