is it possible to use transitions on webkit scrollbars? I tried:
div#main::-webkit-scrollbar-thumb {
background: rgba(255,204,102,0.25);
-webkit-transiti
Short answer: No, it's not possible to use transition on a ::-webkit-scrollbar
Long answer: There are means to achieve a similar effect entirely in CSS.
Explanation:
background-color property. This property will match the color we want to transition on for the scrollbar.background-color that masks the outer container.background-color will inherit the outer container's.transition property will be applied to the background-color of the outer container.A major disadvantage here is that you have to do some masking. This can be a bit of a hassle if your background isn't a solid color, since the inner container will most likely need to match. If that's not a worry, this will work for you. Here's the code to put it all together for a page with a horizontally scrolling component.
HTML
CSS
/* Scrollbar */
::-webkit-scrollbar {
border: 0;
height: 10px;
}
::-webkit-scrollbar-track {
background: rgba(0,0,0,0);
}
::-webkit-scrollbar-thumb {
background-color: inherit; /* Inherits from outer container */
border-radius: 20px;
}
/* Container */
#container-outer {
overflow-y: hidden;
overflow-x: scroll; /* Horizontal-only scrolling */
height: 400px;
background-color: white; /* Initial color of the scrollbar */
transition: background-color 200ms;
}
#container-outer:hover {
background-color: red; /* Hover state color of the scrollbar */
}
#container-inner {
background-color: white; /* Masks outer container */
font-size: 0;
height: inherit; /* Inherits from outer container */
width: 10000px; /* Set to see the scrolling effect */
}
Notes:
max-width that will match whatever your inner container's width is, otherwise you may see some oddity on extremely large displays. This is an edge case for when the browser width is larger than the horizontally scrolling content width. This is assuming you are using a horizontal scroll, as the example code does.