onScreen
onScreen copied to clipboard
Added direction to enter and leave event
Added parameter direction
to 'enter'
and 'leave'
callback.
added sinon for testing, and test for direction parameter.
Hey! Thanks for the Pull Request. The build is failing on Travis CI. Apparently due to some linting issues:
/home/travis/build/silvestreh/onScreen/test/index_test.js
error 'calledCallback' is defined but never used no-unused-vars
error 'calledCallback' is never reassigned, use 'const' instead prefer-const
error Block must not be padded by blank lines padded-blocks
EDIT: Also, the feature seems to only cover vertical scrolling.
Some other things I'm noticing… Would you care to explain these?
- Why would
scrollTop
be public? - Could the
direction
parameter be part of the options object? - What's the benefit of knowing the direction? I'm thinking that you could check which direction you're scrolling outside the library while implementing it in a project… something like:
const os = new OnScreen();
const direction = {
up() { /* implement to return true */ },
down() { /* implement to return true */ },
left() { /* implement to return true */ },
right() { /* implement to return true */ },
};
os.on('enter', (element) => {
if (direction.up) {
// do something
}
});
- Finally: if I end up merging this PR we'll need documentation for it 😄
Thanks!
the feature seems to only cover vertical scrolling
you're right, i'll fix soon
Why would scrollTop be public?
I just put it as object prop, the idea is to set a default value then on scroll (the function debouncedScroll) check the direction
Could the direction parameter be part of the options object?
not sure to understand. you want object direction on options and then set when is on debounceScroll?
What's the benefit of knowing the direction? I'm thinking that you could check which direction you're scrolling outside the library while implementing it in a project
yes, I was able to extends OnScreen also and hack this feature, but why bind another scroll event? With onscreen you can get also direction and decide to use it or not :) For that reason I decided to try improve with this feature.
I will update you with fixes if you want, thanks a lot!
Added direction
object, now you can check with
if(direction.up) { /* tell me baby */ }
test updated.
docs updated ! 👍
build passed on travis it seems ! 🎉
if you don't like something feel free to change, or to tell me what you prefer.
Thank you for feedback! :)
Hi, for internet explorer fix direction I used x: window.pageXOffset || document.documentElement.scrollLeft, y: window.pageYOffset || document.documentElement.scrollTop
Added also pageXOffset and pageYOffset for solving compatibility issue. Thanks @caiter78