sakhnyuk / rc-scrollbars

React scrollbars component
https://rc-scrollbars.vercel.app/
MIT License
145 stars 14 forks source link

element.scrollIntoView with true option #14

Closed JumpAttacker closed 3 years ago

JumpAttacker commented 3 years ago

When im using element.scrollIntoView(true)

foundItem.scrollIntoView({
        block: "center" // or 'start'
        behavior: "smooth"
      });

scroll working is not correnctly

reproduce link https://codesandbox.io/s/react-fiddle-forked-bvesc?file=/src/App.js

Tomassito commented 3 years ago

Is this what you want to achieve? https://codesandbox.io/s/react-fiddle-forked-h8fvx?file=/src/App.js

BTW. there are functions that you can call on the Scrollbars instance (that you can get a hold of using refs): scrollToTop scrollToBottom scrollToRight scrollToLeft

JumpAttacker commented 3 years ago

i dont need only to btm, some times i need to go not to the last element

and i told you about dat image

i want to use scrollIntoView with options {block: 'center} but if im using it i got dat

for me is hard to use scrollToTop cuz my content height inside this scroll are dynamic

Tomassito commented 3 years ago

You can scroll into any position you like with Scrollbars.scrollTop(placeYouWantToScrollInto). See the Spring Scrollbars example that also uses rebound for a smoother effect. The options you wanted to use are experimental anyway and should not be used.

JumpAttacker commented 3 years ago

but you know easy way to get item's position inside scroll? I only know basic: item.height*x, but i have dynamic height on items, so its hard for me to calc all items (i know it possible, but easiest way to use just scrollIntoView)

Tomassito commented 3 years ago

Element.offsettop would be my first call. Anyway it's more like stackoverflow question than Scrollbars related. As described above, you are encouraged to use the API to scroll within it rather than using scrollInto etc. browser API. Otherwise you may see such artifacts as the original scrollbars being pulled from under the negative margins.

Unless you have any more issues to raise, I assume your case to be closed?

JumpAttacker commented 3 years ago

yes, thanks for help