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
a9add215
Commit
a9add215
authored
Sep 26, 2007
by
Brandon Aaron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
offset: fixes for correct body offsets in safari and mozilla (thanks Wizzud)
parent
92a9e73b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
26 deletions
+15
-26
offset.js
src/offset.js
+15
-26
No files found.
src/offset.js
View file @
a9add215
...
@@ -6,12 +6,11 @@ jQuery.fn.offset = function() {
...
@@ -6,12 +6,11 @@ jQuery.fn.offset = function() {
if
(
elem
)
with
(
jQuery
.
browser
)
{
if
(
elem
)
with
(
jQuery
.
browser
)
{
var
parent
=
elem
.
parentNode
,
var
parent
=
elem
.
parentNode
,
offsetChild
=
elem
,
offsetParent
=
elem
.
offsetParent
,
offsetParent
=
elem
.
offsetParent
,
doc
=
elem
.
ownerDocument
,
doc
=
elem
.
ownerDocument
,
safari2
=
safari
&&
parseInt
(
version
)
<
522
,
safari2
=
safari
&&
parseInt
(
version
)
<
522
,
position
=
jQuery
.
css
(
elem
,
"position"
),
fixed
=
jQuery
.
css
(
elem
,
"position"
)
==
"fixed"
;
absolute
=
position
==
"absolute"
,
fixed
=
position
==
"fixed"
;
// Use getBoundingClientRect if available
// Use getBoundingClientRect if available
if
(
elem
.
getBoundingClientRect
)
{
if
(
elem
.
getBoundingClientRect
)
{
...
@@ -44,35 +43,23 @@ jQuery.fn.offset = function() {
...
@@ -44,35 +43,23 @@ jQuery.fn.offset = function() {
add
(
offsetParent
.
offsetLeft
,
offsetParent
.
offsetTop
);
add
(
offsetParent
.
offsetLeft
,
offsetParent
.
offsetTop
);
// Mozilla and Safari > 2 does not include the border on offset parents
// Mozilla and Safari > 2 does not include the border on offset parents
// However Mozilla adds the border for table cells
// However Mozilla adds the border for table
or table
cells
if
(
mozilla
&&
/^t
[
d|h
]
$/i
.
test
(
parent
.
tagName
)
||
!
safari2
)
if
(
mozilla
&&
!
/^t
(
able|d|h
)
$/i
.
test
(
offsetParent
.
tagName
)
||
safari
&&
!
safari2
)
border
(
offsetParent
);
border
(
offsetParent
);
// Get offsetParent's position
// Add the document scroll offsets if position is fixed on any offsetParent
position
=
jQuery
.
css
(
offsetParent
,
"position"
);
if
(
!
fixed
&&
jQuery
.
css
(
offsetParent
,
"position"
)
==
"fixed"
)
// Safari <= 2 doubles body offsets with an absolutely positioned element or parent
if
(
safari2
&&
!
absolute
&&
position
==
"absolute"
)
absolute
=
true
;
// Opera adds border for fixed, relative and absolute parent elements
if
(
opera
&&
/^fixed|relative|absolute$/i
.
test
(
position
))
add
(
-
parseInt
(
jQuery
.
css
(
elem
,
"borderLeftWidth"
)),
-
parseInt
(
jQuery
.
css
(
elem
,
"borderTopWidth"
))
);
// Add the document scroll offsets if position is fixed
if
(
!
fixed
&&
position
==
"fixed"
)
fixed
=
true
;
fixed
=
true
;
// Set offsetChild to previous offsetParent unless it is the body element
offsetChild
=
/^body$/i
.
test
(
offsetParent
.
tagName
)
?
offsetChild
:
offsetParent
;
// Get next offsetParent
// Get next offsetParent
offsetParent
=
offsetParent
.
offsetParent
;
offsetParent
=
offsetParent
.
offsetParent
;
}
}
// Get parent scroll offsets
// Get parent scroll offsets
while
(
parent
.
tagName
&&
!
/^body|html$/i
.
test
(
parent
.
tagName
)
)
{
while
(
parent
.
tagName
&&
!
/^body|html$/i
.
test
(
parent
.
tagName
)
)
{
//
Work around o
pera inline/table scrollLeft/Top bug
//
Remove parent scroll UNLESS that parent is inline or a table-row to work around O
pera inline/table scrollLeft/Top bug
if
(
!
/^inline|table-row.*$/i
.
test
(
jQuery
.
css
(
parent
,
"display"
))
)
if
(
!
/^inline|table-row.*$/i
.
test
(
jQuery
.
css
(
parent
,
"display"
))
)
// Subtract parent scroll offsets
// Subtract parent scroll offsets
add
(
-
parent
.
scrollLeft
,
-
parent
.
scrollTop
);
add
(
-
parent
.
scrollLeft
,
-
parent
.
scrollTop
);
...
@@ -85,9 +72,11 @@ jQuery.fn.offset = function() {
...
@@ -85,9 +72,11 @@ jQuery.fn.offset = function() {
parent
=
parent
.
parentNode
;
parent
=
parent
.
parentNode
;
}
}
// Safari <= 2 doubles body offsets with an absolute or fixed positioned element or parent
// Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
if
(
safari2
&&
(
absolute
||
fixed
)
)
// Mozilla doubles body offsets with a non-absolutely positioned offsetChild
add
(
-
doc
.
body
.
offsetLeft
,
-
doc
.
body
.
offsetTop
);
if
(
(
safari2
&&
(
fixed
||
jQuery
.
css
(
offsetChild
,
"position"
)
==
"absolute"
))
||
(
mozilla
&&
jQuery
.
css
(
offsetChild
,
"position"
)
!=
"absoltue"
)
)
add
(
-
doc
.
body
.
offsetLeft
,
-
doc
.
body
.
offsetTop
);
// Add the document scroll offsets if position is fixed
// Add the document scroll offsets if position is fixed
if
(
fixed
)
if
(
fixed
)
...
@@ -109,6 +98,6 @@ jQuery.fn.offset = function() {
...
@@ -109,6 +98,6 @@ jQuery.fn.offset = function() {
function
add
(
l
,
t
)
{
function
add
(
l
,
t
)
{
left
+=
parseInt
(
l
)
||
0
;
left
+=
parseInt
(
l
)
||
0
;
top
+=
parseInt
(
t
)
||
0
;
top
+=
parseInt
(
t
)
||
0
;
}
}
};
};
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