skip to Main Content

enter image description here
On mobile devices I want to hide the scrollbar completely thought out the app but I need the user to be able to scroll.

enter image description here

I’ve tried to hide the scrollbar using css scrollbar, scrollbar-thumb, scrollbar-thumb:hover and scrollbar-track it is working in browser but not in mobile browser.

2

Answers


  1. Chosen as BEST ANSWER

    I tried this and it is working as expected.

    enter image description here

    Thank you all for the help.


  2. Using CSS, you can hide the scrollbar on a mobile view without affecting the scroll behaviour. One common approach is using the overflow property and the -webkit-overflow-scrolling property to control scrolling behaviour on mobile devices. Here’s how you can achieve this in a React app:

    Create a CSS class to hide the scrollbar:

     .hide-scrollbar {
        overflow: hidden;
        -webkit-overflow-scrolling: touch;
      }
    

    Apply the hide-scrollbar class conditionally based on the screen size (e.g., for mobile devices) in your React component:

        
    import { useEffect, useState } from 'react';
    import './styles.css';
    
    const App = () => {
       const [isMobile, setIsMobile] = useState(false);
    
       useEffect(() => {
          const handleResize = () => {
          setIsMobile(window.innerWidth <= 768);
       };
    
       handleResize();
       window.addEventListener('resize', handleResize);
    
       return () => {
          window.removeEventListener('resize', handleResize);
       };
      }, []);
    
      return (
        <div className={isMobile ? 'hide-scrollbar' : ''}>
            {/* Your app content */}
        </div>
      );
    };
    
    export default App;
    
    

    the isMobile state determines whether the hide-scrollbar class should be applied. The class hides the scrollbar and maintains smooth scrolling behavior on mobile devices.

    Remember to adjust the breakpoint value (768 in this case) to match your desired mobile viewport width

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search