Fix Element.viewportOffset on nested elements in Opera < 9.5 and remove browser sniff.

(cherry picked from commit 0d2d18fb7297fb945ca6983b843c5bcf367c721c)
This commit is contained in:
Andrew Dupont 2009-11-06 10:56:01 -06:00
parent 093c0cce4b
commit 62d0430f3b
1 changed files with 7 additions and 5 deletions

View File

@ -707,21 +707,23 @@
* Returns the X/Y coordinates of element relative to the viewport.
**/
function viewportOffset(forElement) {
var valueT = 0, valueL = 0;
var valueT = 0, valueL = 0, docBody = document.body;
var element = forElement;
do {
valueT += element.offsetTop || 0;
valueL += element.offsetLeft || 0;
// Safari fix
if (element.offsetParent == document.body &&
if (element.offsetParent == docBody &&
Element.getStyle(element, 'position') == 'absolute') break;
} while (element = element.offsetParent);
element = forElement;
var tagName = element.tagName, O = Prototype.Browser.Opera;
element = forElement;
do {
if (!O || tagName && tagName.toUpperCase() === 'BODY') {
// Opera < 9.5 sets scrollTop/Left on both HTML and BODY elements.
// Other browsers set it only on the HTML element. The BODY element
// can be skipped since its scrollTop/Left should always be 0.
if (element != docBody) {
valueT -= element.scrollTop || 0;
valueL -= element.scrollLeft || 0;
}