Skip to content

Commit 7870156

Browse files
authored
Merge pull request #132 from steevee/master
Fixes #131 - percent correctly translated
2 parents f462b67 + a0ea102 commit 7870156

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

angular-inview.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ function offsetRect (rect, offset) {
222222
return rect;
223223
}
224224
var offsetObject = {
225-
top: isPercent(offset[0]) ? (parseFloat(offset[0]) * rect.height) : offset[0],
226-
right: isPercent(offset[1]) ? (parseFloat(offset[1]) * rect.width) : offset[1],
227-
bottom: isPercent(offset[2]) ? (parseFloat(offset[2]) * rect.height) : offset[2],
228-
left: isPercent(offset[3]) ? (parseFloat(offset[3]) * rect.width) : offset[3]
225+
top: isPercent(offset[0]) ? (parseFloat(offset[0]) * rect.height / 100) : offset[0],
226+
right: isPercent(offset[1]) ? (parseFloat(offset[1]) * rect.width / 100) : offset[1],
227+
bottom: isPercent(offset[2]) ? (parseFloat(offset[2]) * rect.height / 100) : offset[2],
228+
left: isPercent(offset[3]) ? (parseFloat(offset[3]) * rect.width / 100) : offset[3]
229229
};
230230
// Note: ClientRect object does not allow its properties to be written to therefore a new object has to be created.
231231
return {

angular-inview.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ describe("angular-inview", function() {
212212
.then(done);
213213
});
214214

215+
it("should consider percent offset option", function(done) {
216+
makeTestForHtml(
217+
'<div in-view="spy($inviewInfo)" style="height:200px" in-view-options="{ offset:[\'25%\', 0], generateParts: true }"></div>' +
218+
'<div style="height:200%"></div>'
219+
)
220+
.then(function (test) {
221+
var info = test.spy.calls.argsFor(0)[0];
222+
expect(info.inView).toEqual(true);
223+
expect(info.parts).toEqual({
224+
top: false,
225+
left: true,
226+
bottom: true,
227+
right: true
228+
});
229+
return test;
230+
})
231+
.then(done);
232+
});
233+
215234
it("should consider viewport offset options", function(done) {
216235
makeTestForHtml(
217236
'<div in-view="spy($inviewInfo)" style="height:200px" in-view-options="{ viewportOffset:[100, 0], generateParts: true }"></div>' +

0 commit comments

Comments
 (0)