import useCustomIonContentScroll from './useCustomIonContentScroll';
const YourIonPage: React.FC = () => {
const customIonContentScrollRef = useCustomIonContentScroll();
return (
<IonPage className="play-game-page">
...
<IonContent ref={customIonContentScrollRef}>
...
</IonContent>
</IonPage>
);
}
export const YourIonPage;
Last active
November 25, 2022 14:04
-
-
Save bipoza/8f8b4e67e0d9863fe59d185a6fefee26 to your computer and use it in GitHub Desktop.
Ionic React - Custom hook to customize the scrollbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from 'react'; | |
const useCustomIonContentScroll = () => { | |
const ref = useRef(null); | |
const styleScrollbars = (elmt: any) => { | |
const stylesheet = ` | |
::-webkit-scrollbar { | |
width: 10px; | |
} | |
::-webkit-scrollbar-track { | |
padding: 2px 0; | |
border-radius: 15px; | |
} | |
::-webkit-scrollbar-thumb { | |
border-radius: 10px; | |
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); | |
background: var(--ion-color-tertiary); | |
} | |
::-webkit-scrollbar-thumb:hover { | |
// Your customization | |
} | |
`; | |
const styleElmt = elmt.shadowRoot.querySelector('style'); | |
if (styleElmt) { | |
styleElmt.append(stylesheet); | |
} else { | |
const barStyle = document.createElement('style'); | |
barStyle.append(stylesheet); | |
elmt.shadowRoot.appendChild(barStyle); | |
} | |
}; | |
useEffect(() => { | |
styleScrollbars(ref.current); | |
}, [ref]); | |
return ref; | |
}; | |
export default useCustomIonContentScroll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment