import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Home from './Home';
import CommingSoon from './CommingSoon';
import Navbar from './components/Navbar';
import Scroll from './components/SmoothScrollbar';
const App = () => {
return (
<>
<Scroll />
<Navbar/>
<Switch>
<Route exact path="/comming-soon" component={CommingSoon}/>
<Route exact path="/" component={Home}/>
</Switch>
</>
);
};
export default App;
And Here is my SmoothScrollbar.js for setting up Scrolling.
import { useEffect } from 'react';
import Scrollbar from 'smooth-scrollbar';
import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll'
var options = {
damping: 0.05,
plugins: {
overscroll: {...overscrolloptions}
}
}
var overscrolloptions = {
enable: true,
damping: 0.1,
effect: "bounce",
maxOverscroll: 150
}
const Scroll = () => {
useEffect(() => {
Scrollbar.use(OverscrollPlugin);
Scrollbar.init(document.body, options);
}, [])
return null;
}
export default Scroll;
You can get offset values in the following way:
Scrollbar.getAll()[0].addListener(function (status){
var offset = status.offset;
// offset.y
});
I found how to get some offset value
var Scrollbar = window.Scrollbar;
var mainscrollbarOptions = {
'dumping': 0.08
}
const scrollbar = Scrollbar.init(document.querySelector('#my-scrollbar-container'), mainscrollbarOptions);
scrollbar.addListener(({ offset }) => {
console.log( offset.y ); // offset y position
console.log( document.querySelector('#my-element').getBoundingClientRect().top ); // my element distance from top
});