Tips & Tutorial

Styling Scrollbar to Look Like Facebook ScrollableArea Using jScrollPane

Oleh takien• 12 Komentar Arsip
Facebook Scrollable Area

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

<!-- 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.

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

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

$('.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:

$('.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
–

/*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


Tulisan ini sudah berumur: 14 tahun 8 bulan 12 hari. Informasi di dalamnya mungkin sudah tidak relevan, tapi nilai historisnya sangat berharga, terutama bagi saya sebagai penulisnya.

(Dipulihkan dari takien.com)

Tag Terkait:

Komentar (12)

Arsip Statis
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.
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