diff --git a/4chan_x.user.js b/4chan_x.user.js index 8a990db59..e49f56285 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2991,16 +2991,11 @@ } }, toggle: function(a) { - var el, thumb, top; + var thumb, top; thumb = a.firstChild; if (thumb.hidden) { - if (thumb.nextSibling.offsetHeight > window.innerHeight) { - el = thumb.nextSibling; - top = el.offsetTop; - while (el = el.offsetParent) { - top += el.offsetTop; - } - if (top < window.scrollY) window.scroll(window.scrollX, top); + if (thumb.nextSibling.offsetHeight > d.body.clientHeight && (top = a.getBoundingClientRect().top) < 0) { + window.scroll(window.scrollX, window.scrollY + top); } return imgExpand.contract(thumb); } else { diff --git a/script.coffee b/script.coffee index 7f789239c..d4c4aabae 100644 --- a/script.coffee +++ b/script.coffee @@ -2316,12 +2316,8 @@ imgExpand = toggle: (a) -> thumb = a.firstChild if thumb.hidden - if thumb.nextSibling.offsetHeight > window.innerHeight - el = thumb.nextSibling - top = el.offsetTop - while el = el.offsetParent - top += el.offsetTop - window.scroll window.scrollX, top if top < window.scrollY + if thumb.nextSibling.offsetHeight > d.body.clientHeight and (top = a.getBoundingClientRect().top) < 0 + window.scroll window.scrollX, window.scrollY + top imgExpand.contract thumb else imgExpand.expand thumb