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

Suggested change... offset #44

Open
tdsmoore opened this issue Oct 12, 2017 · 0 comments
Open

Suggested change... offset #44

tdsmoore opened this issue Oct 12, 2017 · 0 comments

Comments

@tdsmoore
Copy link

tdsmoore commented Oct 12, 2017

I've seen some really odd results using the offset option. Perhaps I've missed something or the documentation needs updating to make its use clear?

My understanding is that a positive offset should reduce the viewport dimensions top and bottom by the value e.g. :in-viewport(100) would make the viewport shorter by 200 pixels. Conversely, a negative would increase the viewport height allowing detection of objects before they appear on-screen.

The current release works for me if the element starts outside of this new viewport but if I refresh the page and the element is inside the viewport, then :in-viewport(100) returns false until I scroll to a position where the element starts to leave the viewport.

I think that there are 2 issues, first this code - I think it should be removed;

if (settings.tolerance < 0) { settings.tolerance = $viewportHeight + settings.tolerance; // viewport height - tol }

Secondly, this line;

isVisibleFlag = settings.tolerance ? top <= settings.tolerance && bottom >= settings.tolerance : bottom > 0 && top <= $viewportHeight;

I suggest it's changed to;

isVisibleFlag = settings.tolerance ? (bottom >= settings.tolerance && top <= $viewportHeight - settings.tolerance) : bottom > 0 && top <= $viewportHeight;

I now get the results I had expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant