mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Position: Handle decimal percentage offsets. Fixes #9076: percentage offset does not support decimal
This commit is contained in:
parent
ab408c9b82
commit
c958b211db
@ -221,7 +221,7 @@ test( "of", function() {
|
||||
});
|
||||
|
||||
test( "offsets", function() {
|
||||
expect( 4 );
|
||||
expect( 7 );
|
||||
|
||||
$( "#elx" ).position({
|
||||
my: "left top",
|
||||
@ -254,6 +254,30 @@ test( "offsets", function() {
|
||||
collision: "none"
|
||||
});
|
||||
deepEqual( $( "#elx" ).offset(), { top: 65, left: 37 }, "percentage offsets in my" );
|
||||
|
||||
$( "#elx" ).position({
|
||||
my: "left-30.001% top+50.0%",
|
||||
at: "left bottom",
|
||||
of: "#parentx",
|
||||
collision: "none"
|
||||
});
|
||||
deepEqual( $( "#elx" ).offset(), { top: 65, left: 37 }, "decimal percentage offsets in my" );
|
||||
|
||||
$( "#elx" ).position({
|
||||
my: "left+10.4 top-10.6",
|
||||
at: "left bottom",
|
||||
of: "#parentx",
|
||||
collision: "none"
|
||||
});
|
||||
deepEqual( $( "#elx" ).offset(), { top: 49, left: 50 }, "decimal offsets in my" );
|
||||
|
||||
$( "#elx" ).position({
|
||||
my: "left+right top-left",
|
||||
at: "left-top bottom-bottom",
|
||||
of: "#parentx",
|
||||
collision: "none"
|
||||
});
|
||||
deepEqual( $( "#elx" ).offset(), { top: 60, left: 40 }, "invalid offsets" );
|
||||
});
|
||||
|
||||
test( "using", function() {
|
||||
|
6
ui/jquery.ui.position.js
vendored
6
ui/jquery.ui.position.js
vendored
@ -18,15 +18,15 @@ var cachedScrollbarWidth,
|
||||
round = Math.round,
|
||||
rhorizontal = /left|center|right/,
|
||||
rvertical = /top|center|bottom/,
|
||||
roffset = /[\+\-]\d+%?/,
|
||||
roffset = /[\+\-]\d+(\.[\d]+)?%?/,
|
||||
rposition = /^\w+/,
|
||||
rpercent = /%$/,
|
||||
_position = $.fn.position;
|
||||
|
||||
function getOffsets( offsets, width, height ) {
|
||||
return [
|
||||
parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
|
||||
parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
|
||||
parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
|
||||
parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user