diff --git a/iron-fit-behavior.html b/iron-fit-behavior.html index 887b7db..aa776c7 100644 --- a/iron-fit-behavior.html +++ b/iron-fit-behavior.html @@ -91,6 +91,26 @@ return fitHeight; }, + get _fitLeft() { + var fitLeft; + if (this.fitInto === window) { + fitLeft = 0; + } else { + fitLeft = this.fitInto.getBoundingClientRect().left; + } + return fitLeft; + }, + + get _fitTop() { + var fitTop; + if (this.fitInto === window) { + fitTop = 0; + } else { + fitTop = this.fitInto.getBoundingClientRect().top; + } + return fitTop; + }, + attached: function() { if (this.autoFitOnAttach) { if (window.getComputedStyle(this).display === 'none') { @@ -220,12 +240,12 @@ this.style.position = 'fixed'; } if (!this._fitInfo.positionedBy.vertically) { - var top = (this._fitHeight - this.offsetHeight) / 2; + var top = (this._fitHeight - this.offsetHeight) / 2 + this._fitTop; top -= this._fitInfo.margin.top; this.style.top = top + 'px'; } if (!this._fitInfo.positionedBy.horizontally) { - var left = (this._fitWidth - this.offsetWidth) / 2; + var left = (this._fitWidth - this.offsetWidth) / 2 + this._fitLeft; left -= this._fitInfo.margin.left; this.style.left = left + 'px'; } diff --git a/test/iron-fit-behavior.html b/test/iron-fit-behavior.html index 988e8a5..c4011bf 100644 --- a/test/iron-fit-behavior.html +++ b/test/iron-fit-behavior.html @@ -139,7 +139,7 @@