From e2ec1a6f043557dc789e11584c656700c488bce4 Mon Sep 17 00:00:00 2001 From: Haks1 Date: Mon, 6 Jul 2015 14:07:22 +0200 Subject: [PATCH] make it able to flip with relative parents --- flippant.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/flippant.js b/flippant.js index 31f8c8b..db3282a 100644 --- a/flippant.js +++ b/flippant.js @@ -61,8 +61,16 @@ function flip(flipper, content, type, class_name, timeout) { function set_styles(back, front, position) { back.style.position = position - back.style.top = front.offsetTop + "px" - back.style.left = front.offsetLeft + "px" + cur = front + totalLeft = 0 + totalTop = 0 + while (cur) { + totalLeft += cur.offsetLeft; + totalTop += cur.offsetTop; + cur = cur.offsetParent; + } + back.style.top = totalTop + "px" + back.style.left = totalLeft + "px" back.style['min-height'] = front.offsetHeight + "px" back.style.width = front.offsetWidth + "px" back.style["z-index"] = 9999 @@ -80,4 +88,4 @@ function card_styles(back) { } },{}]},{},[1])(1) }); -; \ No newline at end of file +;