1

I have a iOS app that has a WebKit webview (WKWebView) and I want to change the color of the scrollbar in my HTML with CSS while still retaining the touch / throw acceleration scrolling.

I have tried using:

::-webkit-scrollbar-thumb {
    background-color: #ff4872;
}

...but to no avail. Because it doesn't change the color unless I set the webkit scrolling setting to scroll:

-webkit-overflow-scrolling: scroll;

...which takes away the Safari-like acceleration scrolling. I would like a pure CSS solution if possible, but I can do JavaScript or JQuery if that is the only option.

JSFiddle: https://jsfiddle.net/rmcadbmq/3/

3
  • 1
    can you post your html or JsFiddele code please Commented Jul 1, 2015 at 11:53
  • 1
    jsfiddle.net/rmcadbmq/3 Commented Jul 1, 2015 at 12:20
  • @quemeful I'm having this same issue... did you ever find a solution? Commented Feb 9, 2017 at 22:08

2 Answers 2

1

Using Below code you will solve your issue

::-webkit-scrollbar {
    width: 12px;
}
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);     
    border-radius: 10px;
}
::-webkit-scrollbar-thumb {
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
Sign up to request clarification or add additional context in comments.

2 Comments

That code works to change the color. But the main problem is, it requires me to change the -webkit-overflow-scrolling to "scroll" instead of "touch" so I lose the Safari-like scroll acceleration.
Please use of !important of every where then i think your problem wil be solve.
1

I think it will work for you:

.scrollContainer::-webkit-scrollbar-thumb {
    background: #ff4872; 
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(112,0222,0,0.5);

}
.scrollContainer {
    font-size: 2em;
    width: 300px;
    height: 440px;
    background-color: #eee;
    overflow: scroll;
}

.scrollTest {
    width: 270px;
    height: 440px; 
}

4 Comments

try it on a touch screen device...it loses touch momentum scrolling: jsfiddle.net/rmcadbmq/10
What is your actual problem?. I think it solved the color issue
the problem is when I can't change the color when the -webkit-overflow-scrolling is set to "touch" ... I switch it to "scroll" for jsfiddle...10 above
doesn't have momentum scrolling on touch screen devices ... I think this is a big oversight in webkit css

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.