Styling Scrollbar to Look Like Facebook ScrollableArea Using jScrollPane

What Is Scrollbar?

According to Wikipedia, A scrollbar is an object in a graphical user interface (GUI) with which continuous text, pictures or anything else can be scrolled including time in video applications, i.e., viewed even if it does not fit into the space in a computer display, window, or viewport. It was also known as a handle in the very first GUIs.

What Is jScrollPane?

jScrollPane is a cross-browser jQuery plugin by Kelvin Luck which converts a browser’s default scrollbars (on elements with a relevant overflow property) into an HTML structure which can be easily skinned with CSS.

jScrollPane is designed to be flexible but very easy to use. After you have downloaded and included the relevant files in the head of your document all you need to to is call one javascript function to initialise the scrollpane. You can style the resultant scrollbars easily with CSS or choose from the existing themes. There are a number of different examples showcasing different features of jScrollPane and a number of ways for you to get support.

What Is Facebook ScrollableArea?

Facebook Scrollable Area

Facebook Scrollable Area

Recently, Facebook ScrollableArea can be found in many part of Facebook user interface to handle overflow content. One is in the activity feed in the top right area with a cute scrollbar that can be scrolled by dragging and mouse scroll.

Yes, it can be done nicely — with little CSS and JavaScript customization — using jScrollPane I mentioned above

jScrollPane + (JavaScript + CSS) = Facebook ScrollableArea

Don’t worry, there is no pain coding needed to do this, just follow this steps:

1. Include jScrollPane library and jQuery (if not yet) to your page

1
2
3
4
5
6
7
8
9
10
11
12
<!-- styles needed by jScrollPane -->
<link type="text/css" href="style/jquery.jscrollpane.css" rel="stylesheet" media="all" />
 
<!-- latest jQuery direct from google's CDN -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
 
<!-- the mousewheel plugin - optional to provide mousewheel support -->
<script type="text/javascript" src="script/jquery.mousewheel.js"></script>
 
<!-- the jScrollPane script -->
<script type="text/javascript" src="script/jquery.jscrollpane.min.js"></script>
<!-- styles needed by jScrollPane -->
<link type="text/css" href="style/jquery.jscrollpane.css" rel="stylesheet" media="all" />

<!-- latest jQuery direct from google's CDN -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>

<!-- the mousewheel plugin - optional to provide mousewheel support -->
<script type="text/javascript" src="script/jquery.mousewheel.js"></script>

<!-- the jScrollPane script -->
<script type="text/javascript" src="script/jquery.jscrollpane.min.js"></script>

2.Initialize jScrollPane to your selector.

By default, the following code is ready to convert your scrollbar to  jScrollPane.

1
2
3
$(function() {
    $('.content-area').jScrollPane();
});
$(function() {
	$('.content-area').jScrollPane();
});

But here, we need more settings. It’s should look like this:

1
2
3
4
5
$('.content-area').jScrollPane({
    horizontalGutter:5,
    verticalGutter:5,
    'showArrows': false
});
$('.content-area').jScrollPane({
	horizontalGutter:5,
	verticalGutter:5,
	'showArrows': false
});

3. Scrollbar should be hidden if no mouse over on it.

So, we use .fadeIn() and .fadeOut() jQuery effects:

1
2
3
4
5
6
7
$('.jspDrag').hide();
$('.jspScrollable').mouseenter(function(){
    $(this).find('.jspDrag').stop(true, true).fadeIn('slow');
});
$('.jspScrollable').mouseleave(function(){
    $(this).find('.jspDrag').stop(true, true).fadeOut('slow');
});
$('.jspDrag').hide();
$('.jspScrollable').mouseenter(function(){
    $(this).find('.jspDrag').stop(true, true).fadeIn('slow');
});
$('.jspScrollable').mouseleave(function(){
    $(this).find('.jspDrag').stop(true, true).fadeOut('slow');
});

4. Last but not least, add custom CSS
-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*scrollpane custom CSS*/
.jspVerticalBar {
    width: 8px;
    background: transparent;
    right:10px;
}
 
.jspHorizontalBar {
    bottom: 5px;
    width: 100%;
    height: 8px;
    background: transparent;
}
.jspTrack {
    background: transparent;
}
 
.jspDrag {
    background: url(images/transparent-black.png) repeat;
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    border-radius:4px;
}
 
.jspHorizontalBar .jspTrack,
.jspHorizontalBar .jspDrag {
    float: left;
    height: 100%;
}
 
.jspCorner {
    display:none
}
/*scrollpane custom CSS*/
.jspVerticalBar {
	width: 8px;
	background: transparent;
	right:10px;
}

.jspHorizontalBar {
	bottom: 5px;
	width: 100%;
	height: 8px;
	background: transparent;
}
.jspTrack {
	background: transparent;
}

.jspDrag {
	background: url(images/transparent-black.png) repeat;
	-webkit-border-radius:4px;
	-moz-border-radius:4px;
	border-radius:4px;
}

.jspHorizontalBar .jspTrack,
.jspHorizontalBar .jspDrag {
	float: left;
	height: 100%;
}

.jspCorner {
	display:none
}

We use a 1×1 pixel PNG transparent image for jspDrag background, Download it here (right click, save link/target)

 Live Demo

Click Here to See Live Demo


$10.99 .CO Domains!

Incoming search terms:

  • jspscrollable
  • facebook style scrollbar
  • mouseover scrollbar like facebook jquery
  • scrollbar like facebook
  • facebook scrollbar jquery
  • jquery facebook scrollbar
  • facebook scrollbar
  • facebook scrollbar css
  • facebook like scrollbar
  • facebook style scrollbar jquery
  • Rodolfo Jorge Nemer Nogueira

    Very good post. I recently used this technique to compose the scroll effect.

    Rodolfo Nogueira Curitiba Paraná UFPR Música

    • Anonymous

      yeah, every stuff in famous sites like facebook, google, or twtitter is great to be imitated and applied  since they have mature programmer and or web designer, xD

  • Guest

    i think it does not work in ie.

    • Anonymous

      That doesn’t matter

      • Guest

        and you call yourself a web developer?

        • Anonymous

          yes, Not IE developer. problem?

          • Pedox

            and im called who ??

          • Anonymous

            troll

    • keaglez

      There is no reason it doesn’t work on IE 7 and up. It does work by the way, you lost border-radius but that’s pretty much it.

      @takien:disqus The mouseover event seems to be not reliable, if you hover in and out fast, the scrollbar will repeat fade in/out. CSS3 might help in this case. Or do some checking if animation is playing before calling fadein/out. :)

      • http://fauzieweb.com/ Fauzie

        for the animation problem, you could use the stop() event.

        http://api.jquery.com/stop/

      • Anonymous

        for those who use IE, I confirmed it does work in IE 6 and above.

        @2413c800e6b3406b83ae7f720b62fd8d:disqus fixed missed vendor prefix’s border radius in CSS.

        multiple queued animations problem in fadein/out it also has been fixed, thanks to @fauzie811:disqus . use stop(true, true) since .stop() doesn’t work.

        The article updated, as well as the demo page.
        thanks.

  • Pedox

    it’s great takien… don’t forget for give me Good reputation !!
    im still waiting

  • Rodolfo Jorge Nemer Nogueira

    Great article my friend!

    Rodolfo Nogueira
    UFPR Música Curitiba Paraná

  • Rizz576

    hey very helpful post and thank u for that..can u post an example where the fade in and out of the scroller could be controlled depending on individual div??What im trying to say is, now it works for multiple div but the scrollbar appears in all the divs whenever mousepointer enters in any one of the div.would be thankful

    • Anonymous

      Hello, change $('.jspDrag').stop(true, true).fadeIn('slow');
      to :
      $(this).find('.jspDrag').stop(true, true).fadeIn('slow');

      I also have updated the post in this part:

      $('.jspScrollable').mouseenter(function(){
      $(this).find('.jspDrag').stop(true, true).fadeIn('slow');
      });
      $('.jspScrollable').mouseleave(function(){
      $(this).find('.jspDrag').stop(true, true).fadeOut('slow');
      });

      thank you

  • Rizz576

    got it :)

    • Anonymous

      how did you do that?

  • http://twitter.com/readywebgo Readywebgo

    Very good information. I am still struggling with getting this implemented for dynamic content and, for that matter getting the CSS styling to work. I still end up with a “browser style” scroll bar. Is this the right forum to ask questions?  Thank-you.

    • Anonymous

      You need to reinitialise jScrollPane after dynamic content is loaded.
      Example:


      var pane = $('.content-area')
      pane.jScrollPane({
      horizontalGutter:5,
          verticalGutter:5,
          'showArrows': false
      });
      var api = pane.data('jsp');
      $.get('ajax/test.html', function(data) {
      $('#somediv').html(data);
      api.reinitialise(); //reinitialise
      });

      Also see example documentation of jScrollpane on dynamic content.
      here is the URL
      http://jscrollpane.kelvinluck.com/dynamic_content.html

  • Anonymous

    Your selector was $('.container ')whereas the element you expected was <div id="container">

    Change the selector with $('#container ')

  • cuteprogrammer

    Hi,
    One simple question, how we can adjust with of content-area!? Actually I tried with css but still Horizontal scroll is coming. I really don’t like it. Am using small Div almost 400px with, but your scrolls comes around 800px width may be more. How to fix it!?

    I really wanna thank you for all your help.
    Thanks

    • takien

      The horizontal scroll will automatically come when the content width is wider than the container.however, you can force to hide horizontal scroll with css:


      /* to adjust width*/
      .content-area{ width:400px;
      }


      /*to disable horizontal bar */.
      jspHorizontalBar { display:none;}