-
Notifications
You must be signed in to change notification settings - Fork 342
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
Feat(#32): add Element.scroll/To/By methods #54
Conversation
as mentioned in iamdustan#32, `scrollBy` method (and others) has been added to the Element interface as well by latest draft spec. iamdustan#32 https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface This commit only adds `scrollBy`.
to test in different browers right away.
should allow refactoring `scrollBy` and `scrollIntoView` later on. Would also enable fixing bad fallback for `scrollBy` (in case of bailout).
side effect is that this refactoring eliminates the bad fallback for `Element.scrollBy` (was using `Element.scrollIntoView`, which gives a totally different behavior), and re-uses simply the fallback within `Element.scroll`.
Now added This should address the entire feature suggestion of #32. |
Tested on:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thanks @ghybs. One minor change and it looks good to me!
dist/smoothscroll.js
Outdated
|
||
if (typeof arg0 === 'object') { | ||
arg0.left += this.scrollLeft; | ||
arg0.top += this.scrollTop; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn’t mutate incoming arguments. We’ll likely want to introduce a really small and simple assign
method to handle this.
this.scroll(assign({}, arg0, {
left: this.scrollLeft + arg0.left,
top: this.scrollTop + arg0.top,
behavior: arg0.behavior,
}));
but use a new object instead. Since only `left`, `top` and `behavior` object members are used (at least for now), we do not need to actually clone the full input parameter; just using those 3 members keeps the code simple.
with refactoring of `Element.prototype.scrollBy` so that it does not change the input argument / parameter.
Nice thought about changed input argument. I did not implement a full |
👍 If the spec changes and adds new features we’ll just need to update then. Appreash! |
as per new draft spec version, as mentioned in issue #32
https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface
This PR only addsElement.prototype.scrollBy
, it does not addressscrollTo
nor anything else yet.Also added a dedicated section on the
index.html
demo page for immediate test:https://ghybs.github.io/smoothscroll/
Tested on Firefox 51, Chromium 53, Opera 43.
NOTE: it might be interesting to refactor
Element.prototype.scrollIntoView
call tosmoothScroll
usingscrollableParent.scrollBy
?