Permalink
Browse files

Fix offset issues in IE6/7.

  • Loading branch information...
1 parent fbe5df7 commit 7de40ef5e50ab354b76c16af79419a6ad573a5e3 @kangax committed Mar 31, 2010
Showing with 21 additions and 4 deletions.
  1. +21 −4 javascripts/default.js
View
@@ -22,13 +22,30 @@ var _gaq = [['_setAccount', 'UA-1128111-23'], ['_trackPageview']];
el.style[name] = styles[name];
}
}
+ var getComputedStyle = function(el) { return el.style; },
+ view = document.defaultView;
+ if (view && view.getComputedStyle) {
+ getComputedStyle = function(el){ return view.getComputedStyle(el, ''); };
+ }
+ else if (document.documentElement.currentStyle) {
+ getComputedStyle = function(el){ return el.currentStyle; };
+ }
+ function getOffset(el, direction) {
+ var offsetProp = 'offset' + (direction.charAt(0).toUpperCase() + direction.slice(1)),
+ offsetValue = el[offsetProp],
+ cs;
+ while ((el = el.offsetParent) && (cs = getComputedStyle(el))) {
+ offsetValue += el[offsetProp];
+ }
+ return offsetValue;
+ }
var summaryEls = [ ];
function absolutizeSummaryEls() {
var emEls = document.getElementsByTagName('em');
for (var i = 0, len = emEls.length; i < len; i++) {
- var left = emEls[i].offsetLeft,
- top = emEls[i].offsetTop,
+ var left = getOffset(emEls[i], 'left'),
+ top = getOffset(emEls[i], 'top'),
clone = emEls[i].cloneNode(true);
setElStyles(clone, {
position: 'absolute',
@@ -42,8 +59,8 @@ var _gaq = [['_setAccount', 'UA-1128111-23'], ['_trackPageview']];
var titleClone = titleEl.cloneNode(true);
setElStyles(titleClone, {
position: 'absolute',
- left: titleEl.offsetLeft + 'px',
- top: titleEl.offsetTop + 'px',
+ left: getOffset(titleEl, 'left') + 'px',
+ top: getOffset(titleEl, 'top') + 'px',
width: titleEl.offsetWidth + 'px',
margin: 0
});

0 comments on commit 7de40ef

Please sign in to comment.