3

I'm creating an E-portfolio that would be viewed on either Chrome or Safari. I've already tried using the code:

$(document).ready(function(){       
            var scroll_pos = 0;
            $(document).scroll(function() { 
                scroll_pos = $(this).scrollTop();
                if(scroll_pos < 2251) {
                    $("body::-webkit-scrollbar-thumb").css('background-color', '#1E791E');
                } else {
                    $("body::-webkit-scrollbar-thumb").css('background-color', '#FF7A00');
                }
            });
        });
user3797115
  • 41
  • 1
  • 4

1 Answers1

0

The .css() method applies CSS properties to an element.

::webkit-scrollbar-* are CSS selectors that select pseudo-elements.
jQuery does not have any methods that interact with pseudo-elements.

Instead, you can create a class with the ::webkit-scrollbar pseudo-elements and use jQuery to add that class when you want to make your adjustment.

CSS

.test::-webkit-scrollbar {
       // your code here
}

jQuery

$('body').addClass('test');

Also, found this JSFiddle here

http://jsfiddle.net/promatik/wZwJz/18/

Which could be useful for you!

Solution #2: JQuery Plugin

jScrollPane - cross browser styleable scrollbars with jQuery and CSS

Community
  • 1
  • 1
imbondbaby
  • 6,351
  • 3
  • 21
  • 54