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
0654711e
Commit
0654711e
authored
Oct 16, 2014
by
Richard McDaniel
Committed by
Timmy Willison
May 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Offset: account for scroll when calculating position
Fixes gh-1708 Close gh-1714
parent
b35bea14
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
offset.js
src/offset.js
+5
-2
offset.js
test/unit/offset.js
+12
-1
No files found.
src/offset.js
View file @
0654711e
...
@@ -137,8 +137,11 @@ jQuery.fn.extend({
...
@@ -137,8 +137,11 @@ jQuery.fn.extend({
}
}
// Add offsetParent borders
// Add offsetParent borders
parentOffset
.
top
+=
jQuery
.
css
(
offsetParent
[
0
],
"borderTopWidth"
,
true
);
// Subtract offsetParent scroll positions
parentOffset
.
left
+=
jQuery
.
css
(
offsetParent
[
0
],
"borderLeftWidth"
,
true
);
parentOffset
.
top
+=
jQuery
.
css
(
offsetParent
[
0
],
"borderTopWidth"
,
true
)
-
offsetParent
.
scrollTop
();
parentOffset
.
left
+=
jQuery
.
css
(
offsetParent
[
0
],
"borderLeftWidth"
,
true
)
-
offsetParent
.
scrollLeft
();
}
}
// Subtract parent offsets and element margins
// Subtract parent offsets and element margins
...
...
test/unit/offset.js
View file @
0654711e
...
@@ -412,7 +412,7 @@ testIframe("offset/table", "table", function( $ ) {
...
@@ -412,7 +412,7 @@ testIframe("offset/table", "table", function( $ ) {
});
});
testIframe
(
"offset/scroll"
,
"scroll"
,
function
(
$
,
win
)
{
testIframe
(
"offset/scroll"
,
"scroll"
,
function
(
$
,
win
)
{
expect
(
2
4
);
expect
(
2
8
);
// If we're going to bastardize the tests, let's just DO it
// If we're going to bastardize the tests, let's just DO it
var
ie
=
/msie 8/i
.
test
(
navigator
.
userAgent
);
var
ie
=
/msie 8/i
.
test
(
navigator
.
userAgent
);
...
@@ -473,6 +473,17 @@ testIframe("offset/scroll", "scroll", function( $, win ) {
...
@@ -473,6 +473,17 @@ testIframe("offset/scroll", "scroll", function( $, win ) {
notEqual
(
$
().
scrollLeft
(
null
),
null
,
"jQuery().scrollLeft(null) testing setter on empty jquery object"
);
notEqual
(
$
().
scrollLeft
(
null
),
null
,
"jQuery().scrollLeft(null) testing setter on empty jquery object"
);
strictEqual
(
$
().
scrollTop
(),
null
,
"jQuery().scrollTop(100) testing setter on empty jquery object"
);
strictEqual
(
$
().
scrollTop
(),
null
,
"jQuery().scrollTop(100) testing setter on empty jquery object"
);
strictEqual
(
$
().
scrollLeft
(),
null
,
"jQuery().scrollLeft(100) testing setter on empty jquery object"
);
strictEqual
(
$
().
scrollLeft
(),
null
,
"jQuery().scrollLeft(100) testing setter on empty jquery object"
);
// Tests position after parent scrolling (#15239)
$
(
"#scroll-1"
).
scrollTop
(
0
);
$
(
"#scroll-1"
).
scrollLeft
(
0
);
equal
(
$
(
"#scroll-1-1"
).
position
().
top
,
6
,
"jQuery('#scroll-1-1').position().top unaffected by parent scrolling"
);
equal
(
$
(
"#scroll-1-1"
).
position
().
left
,
6
,
"jQuery('#scroll-1-1').position().left unaffected by parent scrolling"
);
$
(
"#scroll-1"
).
scrollTop
(
5
);
$
(
"#scroll-1"
).
scrollLeft
(
5
);
equal
(
$
(
"#scroll-1-1"
).
position
().
top
,
6
,
"jQuery('#scroll-1-1').position().top unaffected by parent scrolling"
);
equal
(
$
(
"#scroll-1-1"
).
position
().
left
,
6
,
"jQuery('#scroll-1-1').position().left unaffected by parent scrolling"
);
});
});
testIframe
(
"offset/body"
,
"body"
,
function
(
$
)
{
testIframe
(
"offset/body"
,
"body"
,
function
(
$
)
{
...
...
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