Can the website set scrollbar position in React?
I want to set the tag with the 75% of horizontal scrollbar when user enter the website.
I wonder if the web do this? And how to do.
I ask for chatgpt but its answer is not work.(It provides something like tableRef.current
,table.scrollLeft = table.scrollWidth - table.clientWidth;
, )
The code woulb be like this:
const MyComponent = () => {
return (
<div
style={{
width: '300px',
overflowX: 'scroll',
overflowY: 'scroll',
height: '300px',
}}
>
<table style={{ width: '600px' }}>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 1, Column 1 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
<td>
Row 1, Column 2 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
<td>
Row 1, Column 3 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
</tr>
<tr>
<td>
Row 2, Column 1 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
<td>
Row 2, Column 2 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
<td>
Row 2, Column 3 - Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
</td>
</tr>
</tbody>
</table>
</div>
)
}
function App() {
return (
<div className='App'>
<MyComponent />
</div>
)
}
export default App
expect is: