Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript custom scroll js with same behaviour as default

I have taken a horizontal scroll bar inside a div.

        <div id="custom_scroll" style="width: 91%; overflow: auto; margin: 0 3%;">
            <div id="custom_scroll_child" style="width: 100%">
                &nbsp;
            </div>
        </div>

I increase width of inner div#custom_scroll_child. But these scrollbar is not visible in mobile. So i want to include js library.

When i add any js library like mCustomScrollbar, It's scrollbar width and scroll left is not matching compared to default scroll bar.

So i want design of custom scrollbar. But want behaviour of native scrollbar.

So how can i achieve this? Please guide me.

like image 503
Ricky ponting Avatar asked Jun 12 '18 12:06

Ricky ponting


1 Answers

try the following .

<style>
    body {
        margin: 0px;
        padding: 0px;
        color: black;
    }
    .custom_scroll {
        width: 91%;
        overflow: auto;
        margin: 0 3%;
        height: 200px;
        border: 1px solid red;
    }
    .custom_scroll_child {width: 120%;}

    /* Here you can easily customize it*/
    body ::-webkit-scrollbar {-webkit-appearance: none;}
    body ::-webkit-scrollbar:vertical {width: 12px;}
    body ::-webkit-scrollbar:horizontal {height: 12px;}
    body ::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.5);
        border-radius: 10px;
        border: 2px solid #ff0;
    }
    body ::-webkit-scrollbar-track {
        border-radius: 10px;
        background-color: #f0f;
    }
</style>
<div class="custom_scroll">
    <div class="custom_scroll_child">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. At consectetur nam repudiandae odit illo minima dolorum nihil voluptatibus blanditiis recusandae culpa esse mollitia facere quasi, dignissimos, aperiam iure optio reiciendis?
    </div>
</div>

here a jsfiddle

like image 157
fedeghe Avatar answered Oct 06 '22 00:10

fedeghe