Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #131 - percent correctly translated #132

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions angular-inview.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ function offsetRect (rect, offset) {
return rect;
}
var offsetObject = {
top: isPercent(offset[0]) ? (parseFloat(offset[0]) * rect.height) : offset[0],
right: isPercent(offset[1]) ? (parseFloat(offset[1]) * rect.width) : offset[1],
bottom: isPercent(offset[2]) ? (parseFloat(offset[2]) * rect.height) : offset[2],
left: isPercent(offset[3]) ? (parseFloat(offset[3]) * rect.width) : offset[3]
top: isPercent(offset[0]) ? (parseFloat(offset[0]) * rect.height / 100) : offset[0],
right: isPercent(offset[1]) ? (parseFloat(offset[1]) * rect.width / 100) : offset[1],
bottom: isPercent(offset[2]) ? (parseFloat(offset[2]) * rect.height / 100) : offset[2],
left: isPercent(offset[3]) ? (parseFloat(offset[3]) * rect.width / 100) : offset[3]
};
// Note: ClientRect object does not allow its properties to be written to therefore a new object has to be created.
return {
Expand Down
19 changes: 19 additions & 0 deletions angular-inview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ describe("angular-inview", function() {
.then(done);
});

it("should consider percent offset option", function(done) {
makeTestForHtml(
'<div in-view="spy($inviewInfo)" style="height:200px" in-view-options="{ offset:[\'25%\', 0], generateParts: true }"></div>' +
'<div style="height:200%"></div>'
)
.then(function (test) {
var info = test.spy.calls.argsFor(0)[0];
expect(info.inView).toEqual(true);
expect(info.parts).toEqual({
top: false,
left: true,
bottom: true,
right: true
});
return test;
})
.then(done);
});

it("should consider viewport offset options", function(done) {
makeTestForHtml(
'<div in-view="spy($inviewInfo)" style="height:200px" in-view-options="{ viewportOffset:[100, 0], generateParts: true }"></div>' +
Expand Down