Skip to content

Commit 0da5f99

Browse files
committed
Revert "Position: Use absolute positioning when getting scrollbar width to avoid reflows of user content. Fixes #9291 - Position - $.position.scrollbarWidth detection causes layout issues."
This reverts commit 1d3b8ff.
1 parent 1d3b8ff commit 0da5f99

File tree

2 files changed

+105
-47
lines changed

2 files changed

+105
-47
lines changed

demos/position/default.html

Lines changed: 104 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,68 +12,126 @@
1212
<script src="../../ui/jquery.ui.position.js"></script>
1313
<link rel="stylesheet" href="../demos.css">
1414
<style>
15-
body {
16-
margin: 0;
17-
padding: 0;
15+
#parent {
16+
width: 60%;
17+
height: 40px;
18+
margin: 10px auto;
19+
padding: 5px;
20+
border: 1px solid #777;
21+
background-color: #fbca93;
22+
text-align: center;
1823
}
19-
body > div[style*='display'] {
20-
/* Workaround */
21-
/* position: absolute; */
24+
.positionable {
25+
position: absolute;
26+
display: block;
27+
right: 0;
28+
bottom: 0;
29+
background-color: #bcd5e6;
30+
text-align: center;
2231
}
23-
.blue {
24-
background: blue;
25-
float: left;
26-
width: 100px;
32+
#positionable1 {
33+
width: 75px;
34+
height: 75px;
2735
}
28-
.red {
29-
background: red;
30-
float: left;
31-
overflow-y: hidden;
36+
#positionable2 {
37+
width: 120px;
38+
height: 40px;
3239
}
33-
.content {
34-
width: 2000px;
35-
height: 400px;
36-
border: 2px solid white;
40+
select, input {
41+
margin-left: 15px;
3742
}
38-
#uiPosition {
39-
width: 100px;
40-
height: 100px;
41-
background: #ccc;
42-
}
43-
4443
</style>
4544
<script>
4645
$(function() {
47-
$( "#redBlock" ).css({
48-
width: $( window ).width() - $( "#blueBlock" ).width()
49-
});
50-
$( ".block" ).css({
51-
height: $( window ).height()
52-
});
46+
function position() {
47+
$( ".positionable" ).position({
48+
of: $( "#parent" ),
49+
my: $( "#my_horizontal" ).val() + " " + $( "#my_vertical" ).val(),
50+
at: $( "#at_horizontal" ).val() + " " + $( "#at_vertical" ).val(),
51+
collision: $( "#collision_horizontal" ).val() + " " + $( "#collision_vertical" ).val()
52+
});
53+
}
5354

54-
$( "button" ).on('click', function (e) {
55-
$( "#uiPosition" )
56-
.position({
57-
my: "left top",
58-
at: "left bottom",
59-
of: e.target,
60-
within: $( "#redBlock" ),
61-
collision: "flip"
62-
});
55+
$( ".positionable" ).css( "opacity", 0.5 );
56+
57+
$( "select, input" ).bind( "click keyup change", position );
58+
59+
$( "#parent" ).draggable({
60+
drag: position
6361
});
62+
63+
position();
6464
});
6565
</script>
6666
</head>
6767
<body>
6868

69-
<div class="block blue" id="blueBlock"></div>
70-
<div class="block red" id="redBlock">
71-
<div class="content">
72-
<button>Position</button>
73-
</div>
74-
</div>
69+
<div id="parent">
70+
<p>
71+
This is the position parent element.
72+
</p>
73+
</div>
74+
75+
<div class="positionable" id="positionable1">
76+
<p>
77+
to position
78+
</p>
79+
</div>
80+
81+
<div class="positionable" id="positionable2">
82+
<p>
83+
to position 2
84+
</p>
85+
</div>
7586

76-
<div id="uiPosition"></div>
87+
<div style="padding: 20px; margin-top: 75px;">
88+
position...
89+
<div style="padding-bottom: 20px;">
90+
<b>my:</b>
91+
<select id="my_horizontal">
92+
<option value="left">left</option>
93+
<option value="center">center</option>
94+
<option value="right">right</option>
95+
</select>
96+
<select id="my_vertical">
97+
<option value="top">top</option>
98+
<option value="center">center</option>
99+
<option value="bottom">bottom</option>
100+
</select>
101+
</div>
102+
<div style="padding-bottom: 20px;">
103+
<b>at:</b>
104+
<select id="at_horizontal">
105+
<option value="left">left</option>
106+
<option value="center">center</option>
107+
<option value="right">right</option>
108+
</select>
109+
<select id="at_vertical">
110+
<option value="top">top</option>
111+
<option value="center">center</option>
112+
<option value="bottom">bottom</option>
113+
</select>
114+
</div>
115+
<div style="padding-bottom: 20px;">
116+
<b>collision:</b>
117+
<select id="collision_horizontal">
118+
<option value="flip">flip</option>
119+
<option value="fit">fit</option>
120+
<option value="flipfit">flipfit</option>
121+
<option value="none">none</option>
122+
</select>
123+
<select id="collision_vertical">
124+
<option value="flip">flip</option>
125+
<option value="fit">fit</option>
126+
<option value="flipfit">flipfit</option>
127+
<option value="none">none</option>
128+
</select>
129+
</div>
130+
</div>
77131

132+
<div class="demo-description">
133+
<p>Use the form controls to configure the positioning, or drag the positioned element to modify its offset.
134+
<br>Drag around the parent element to see collision detection in action.</p>
135+
</div>
78136
</body>
79137
</html>

ui/jquery.ui.position.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ $.position = {
7070
return cachedScrollbarWidth;
7171
}
7272
var w1, w2,
73-
div = $( "<div style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
73+
div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
7474
innerDiv = div.children()[0];
7575

7676
$( "body" ).append( div );

0 commit comments

Comments
 (0)