MasterSlaveScroll
is a React component allowing users to create a fixed side menu whcich is longer than the viewport and scrolls along with the main page in sync.
A Demo is available here.
- Install
react-master-slave-scroll
using npm.npm install react-master-slave-scroll
- Import
react-master-slave-scroll
to useMasterSlaveScroll, Master and Slave
components.
import React from 'react';
import ReactDOM from 'react-dom';
import MasterSlaveScroll, {Master, Slave} from 'react-master-slave-scroll';
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<MasterSlaveScroll
slaveWidthPx={300}
>
<Slave>
<div style={{background:"red", height:"130vh"}}>
<p>top</p>
<p style={{position:"absolute", bottom:"0"}}>bottom</p>
</div>
</Slave>
<Master>
<div style={{background:"yellow", height: "160vh"}}></div>
</Master>
</MasterSlaveScroll>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
Set min-width
attribute to MasterSlaveScroll component.
Set width
attribute to slave component.
Fix the slave to right. By default it is false
Set scroll listener delay in milliseconds.
Set animation duration for slave scroll in milliseconds.
This function is called on vertical scroll.
This function is called on horizontal scroll.
Working on it to make it more robust and configurable.