Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fasani/7987203 to your computer and use it in GitHub Desktop.
Save Fasani/7987203 to your computer and use it in GitHub Desktop.
A Pen by Michael Fasani.

How to add a second scroll bar to jScrollPane

I needed to have a scroll bars at the top and bottom of my container, this is how you can do that with the jScrollPane API events.

A Pen by Michael Fasani on CodePen.

License.

<link type="text/css" href="http://jscrollpane.kelvinluck.com/style/jquery.jscrollpane.css" rel="stylesheet" media="all" />
<div class="scroll-pane horizontal-only">
<p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.</p>
<p>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
</div>
$(document).ready(function() {
var $bottom_bar,
$top_bar;
//Listen for the initalization event.
$('.scroll-pane').bind('jsp-initialised', function(event) {
//Locate the bottom scroller and clone it, with events
//add ID attibute to both the top and bottom bars.
$('.jspHorizontalBar')
.attr('id', 'jspHorizontalBarBottom')
.clone(true, true)
.attr('id', 'jspHorizontalBarTop')
.css({'position':'relative'})
.insertBefore('.scroll-pane');
$bottom_bar = $('div#jspHorizontalBarBottom').find('.jspDrag');
$top_bar = $('div#jspHorizontalBarTop').find('.jspDrag');
})
//Listen for scroll events on the x axis.
.bind('jsp-scroll-x', function(event, scrollPositionX, isAtLeft, isAtRight) {
//Get the position of the bottom bar x axis and duplicate to the top bar.
if (typeof $bottom_bar != 'undefined') {
$top_bar.css({'left':$bottom_bar.position().left + 'px'});
}
//Add and remove classes to the arrow buttons.
$('.jspArrow').removeClass('jspDisabled');
if (isAtRight) {
$('.jspArrowRight').addClass('jspDisabled');
}
if (isAtLeft) {
$('.jspArrowLeft').addClass('jspDisabled');
}
})
//Init the jScrollPane with Arrows
.jScrollPane({
showArrows: true
});
});
body {
font-family: Arial;
margin: 0;
}
body .scroll-pane {
height: 150px;
width: 600px;
background: white;
}
body .scroll-pane p {
width: 1000px;
margin: 0 0 10px 0;
}
body .jspHorizontalBar {
background: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment