diff --git a/website_animate/static/src/js/o_animate.frontend.js b/website_animate/static/src/js/o_animate.frontend.js index fe36115de..5de3e3bb6 100644 --- a/website_animate/static/src/js/o_animate.frontend.js +++ b/website_animate/static/src/js/o_animate.frontend.js @@ -52,10 +52,8 @@ var WebsiteAnimate = { var state = $el.css("animation-play-state"); // We need to offset for the change in position from some animation - // So we get the top value of the transform matrix - var transformMatrix = $el.css('transform').replace(/[^0-9\-.,]/g, '').split(','); - var transformOffset = transformMatrix[13] || transformMatrix[5]; - var elTop = $el.offset().top - transformOffset; + // So we get the top value by not taking CSS transforms into calculations + var elTop = self.getElementOffsetTop($el[0]); var visible = windowBottom > (elTop + elOffset) && windowTop < (elTop + elHeight - elOffset); @@ -98,6 +96,17 @@ var WebsiteAnimate = { }); }); }, + + // Get element top offset by not taking CSS transforms into calculations + getElementOffsetTop: function (el) { + // Loop through the DOM tree and add its parent's offset to get page offset + var top = 0; + do { + top += el.offsetTop || 0; + el = el.offsetParent; + } while (el); + return top; + }, }; publicWidget.registry.WebsiteAnimate = publicWidget.Widget.extend({