-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scrollLeft and scrollTop to work with non-windows (#344)
Co-authored-by: Peter Abbondanzo <[email protected]>
- Loading branch information
1 parent
5c79fb7
commit 3db8947
Showing
2 changed files
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
function scrollLeft(el, value) { | ||
var win; | ||
if (el.window === el) { | ||
win = el; | ||
} else if (el.nodeType === 9) { | ||
win = el.defaultView; | ||
} | ||
|
||
if (value === undefined) { | ||
return el.pageXOffset; | ||
return win ? win.pageXOffset : el.scrollLeft; | ||
} | ||
|
||
if (win) { | ||
win.scrollTo(value, win.pageYOffset); | ||
} else { | ||
if (el === window || el.nodeType === 9) { | ||
el.scrollTo(value, el.pageYOffset); | ||
} else { | ||
el.pageXOffset = value; | ||
} | ||
el.scrollLeft = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
function scrollTop(el, value) { | ||
var win; | ||
if (el.window === el) { | ||
win = el; | ||
} else if (el.nodeType === 9) { | ||
win = el.defaultView; | ||
} | ||
|
||
if (value === undefined) { | ||
return el.pageYOffset; | ||
return win ? win.pageYOffset : el.scrollTop; | ||
} | ||
|
||
if (win) { | ||
win.scrollTo(win.pageXOffset, value); | ||
} else { | ||
if (el === window || el.nodeType === 9) { | ||
el.scrollTo(el.pageXOffset, value); | ||
} else { | ||
el.pageYOffset = value; | ||
} | ||
el.scrollTop = value; | ||
} | ||
} |