You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 11, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 11, 2023. It is now read-only.
The first param to Scrolls .to() method is x, which is the horizontal scroll on the x axis, yes. But its not currently being used. I made the decision to include it so that future horizontal support will be easy. the API has since been changed. See updated README.
No it isn't unfortunately. 😞 Just haven't had time to get to it. But do a lot of people need this? Horizontal scrolling seems rare when compared to vertical scrolling and haven't really seen this ticket gain as much popularity. I am open to accepting PRs though if you think its something you can tackle.
No worries! Needed it for a Netflix type navigation with a lot of titles being shown horizontally. Trying to get it working with the the browser native scrolling behavior: smooth for now but I'll revisit this if we cannot get it to work reliably.
We're already using this library for some other scrolling and it's been really great this far 😃
Thanks!
I've hacked together some changes for scrollTo to accept x and y scrolling. This just works for the scrollTo function, it can be translated to the other methods but would require a bit more consideration to update all methods etc.
asyncfunctionscrollTo(el=window,options={}){constscroll=({
from,
to,
startTime,
duration =400,
easeFunc,
resolve,})=>{window.requestAnimationFrame(()=>{constcurrentTime=Date.now();consttime=Math.min(1,(currentTime-startTime)/duration);if(from.top===to.top&&from.left===to.left){returnresolve ? resolve() : null;}setScrollPosition(el,{top: easeFunc(time)*(to.top-from.top)+from.top,left: easeFunc(time)*(to.left-from.left)+from.left,});/* prevent scrolling, if already there, or at end */if(time<1){scroll({ from, to, startTime, duration, easeFunc, resolve });}elseif(resolve){resolve();}});};constcurrentScrollPosition=getScrollPosition(el);returnnewPromise(resolve=>{scroll({from: currentScrollPosition,to: {top: options.top,left: options.left},startTime: Date.now(),duration: options.duration,easeFunc: t=>{returnt*(2-t);},
resolve,});});}functiongetScrollPosition(el){if(el===document.body||el===document.documentElement||elinstanceofWindow){return{top: document.body.scrollTop||document.documentElement.scrollTop,left: document.body.scrollLeft||document.documentElement.scrollLeft,};}else{return{top: el.scrollTop||el.scrollTop,left: el.scrollLeft||el.scrollLeft,};}}functionsetScrollPosition(el,{ top, left }){if(el===document.body||el===document.documentElement||elinstanceofWindow){document.body.scrollTop=top;document.documentElement.scrollTop=top;document.body.scrollLeft=left;document.documentElement.scrollLeft=left;}else{el.scrollTop=top;el.scrollLeft=left;}}
I can have a look at some point! I hacked this together quickly for a small personal project I'm working on but would be happy to contribute for others to use also
Activity
jvgomg commentedon Jan 4, 2016
@mkay581 isn't the first param the X scroll?
markcellus commentedon Jan 4, 2016
The first param to Scrollsthe API has since been changed. See updated README..to()method isx, which is the horizontal scroll on the x axis, yes. But its not currently being used. I made the decision to include it so that future horizontal support will be easy.svensson-david commentedon Mar 20, 2019
Is horizontal scroll still not supported?
markcellus commentedon Mar 22, 2019
No it isn't unfortunately. 😞 Just haven't had time to get to it. But do a lot of people need this? Horizontal scrolling seems rare when compared to vertical scrolling and haven't really seen this ticket gain as much popularity. I am open to accepting PRs though if you think its something you can tackle.
svensson-david commentedon Mar 22, 2019
No worries! Needed it for a Netflix type navigation with a lot of titles being shown horizontally. Trying to get it working with the the browser native scrolling
behavior: smoothfor now but I'll revisit this if we cannot get it to work reliably.We're already using this library for some other scrolling and it's been really great this far 😃
Thanks!
omonk commentedon Aug 4, 2020
I've hacked together some changes for
scrollToto accept x and y scrolling. This just works for the scrollTo function, it can be translated to the other methods but would require a bit more consideration to update all methods etc.markcellus commentedon Aug 5, 2020
Awesome @omonk! You mind submitting a PR? So I can better evaluate, run tests, etc?
omonk commentedon Aug 5, 2020
I can have a look at some point! I hacked this together quickly for a small personal project I'm working on but would be happy to contribute for others to use also
brandonmcconnell commentedon Jul 20, 2022
Would also be excited to see this added ☝🏼 @markcellus @omonk