Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
a3b8ac41
Commit
a3b8ac41
authored
Jul 19, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrote .offsetParent() to work against the full jQuery set, added tests. Fixes #4922.
parent
f0681d98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
offset.js
src/offset.js
+7
-5
offset.js
test/unit/offset.js
+26
-1
No files found.
src/offset.js
View file @
a3b8ac41
...
@@ -147,11 +147,13 @@ jQuery.fn.extend({
...
@@ -147,11 +147,13 @@ jQuery.fn.extend({
},
},
offsetParent
:
function
()
{
offsetParent
:
function
()
{
var
offsetParent
=
this
[
0
].
offsetParent
||
document
.
body
;
return
this
.
map
(
function
(){
while
(
offsetParent
&&
(
!
/^body|html$/i
.
test
(
offsetParent
.
tagName
)
&&
jQuery
.
css
(
offsetParent
,
'position'
)
===
'static'
)
)
{
var
offsetParent
=
this
.
offsetParent
||
document
.
body
;
offsetParent
=
offsetParent
.
offsetParent
;
while
(
offsetParent
&&
(
!
/^body|html$/i
.
test
(
offsetParent
.
tagName
)
&&
jQuery
.
css
(
offsetParent
,
'position'
)
===
'static'
)
)
{
}
offsetParent
=
offsetParent
.
offsetParent
;
return
jQuery
(
offsetParent
);
}
return
offsetParent
;
});
}
}
});
});
...
...
test/unit/offset.js
View file @
a3b8ac41
...
@@ -145,7 +145,32 @@ testoffset("body", function( jQuery ) {
...
@@ -145,7 +145,32 @@ testoffset("body", function( jQuery ) {
equals
(
jQuery
(
'body'
).
offset
().
left
,
1
,
"jQuery('#body').offset().left"
);
equals
(
jQuery
(
'body'
).
offset
().
left
,
1
,
"jQuery('#body').offset().left"
);
});
});
test
(
"offsetParent"
,
function
(){
expect
(
11
);
var
body
=
jQuery
(
"body"
).
offsetParent
();
equals
(
body
.
length
,
1
,
"Only one offsetParent found."
);
equals
(
body
[
0
],
document
.
body
,
"The body is its own offsetParent."
);
var
header
=
jQuery
(
"#header"
).
offsetParent
();
equals
(
header
.
length
,
1
,
"Only one offsetParent found."
);
equals
(
header
[
0
],
document
.
body
,
"The body is the offsetParent."
);
var
div
=
jQuery
(
"#nothiddendivchild"
).
offsetParent
();
equals
(
div
.
length
,
1
,
"Only one offsetParent found."
);
equals
(
div
[
0
],
document
.
body
,
"The body is the offsetParent."
);
jQuery
(
"#nothiddendiv"
).
css
(
"position"
,
"relative"
);
div
=
jQuery
(
"#nothiddendivchild"
).
offsetParent
();
equals
(
div
.
length
,
1
,
"Only one offsetParent found."
);
equals
(
div
[
0
],
jQuery
(
"#nothiddendiv"
)[
0
],
"The div is the offsetParent."
);
div
=
jQuery
(
"body, #nothiddendivchild"
).
offsetParent
();
equals
(
div
.
length
,
2
,
"Two offsetParent found."
);
equals
(
div
[
0
],
document
.
body
,
"The body is the offsetParent."
);
equals
(
div
[
1
],
jQuery
(
"#nothiddendiv"
)[
0
],
"The div is the offsetParent."
);
});
function
testoffset
(
name
,
fn
)
{
function
testoffset
(
name
,
fn
)
{
...
@@ -177,4 +202,4 @@ function testoffset(name, fn) {
...
@@ -177,4 +202,4 @@ function testoffset(name, fn) {
iframe
.
contentWindow
.
location
=
src
;
iframe
.
contentWindow
.
location
=
src
;
return
iframe
;
return
iframe
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment