felis. Vestibulum iaculis mauris non lectus. Suspendisse libero arcu, fermentum at, eleifend
non, fringilla eu, lectus. Mauris sit amet tortor. Proin accumsan mauris sit amet mauris.There are basically two parts to this effect, the scrolling display, and the scrollbar.
The scrolling display consists of a container div (scroll_container), a scrolling div (scroller), and the content divs (scroller div)
The width and height of the scroll_container are stated in the css rule scroll_container, the width of the scrolling div is dynamically calculated by the script. The default width of the content divs, as well as margin and padding etc, are stated in the css rule scroller div and are applied to all the content divs. If the margins are not required they must be set to zero in the css rule scroller div, you can also use inline css in any of the content divs to over-ride the default values.
The scrollbar is made up of a container div (slider_container) and a sliding div (slider)
The width of the slider_container is stated in the css rule slider_container
The image used for the slider is applied as the background for the sliding div, the width and height of the sliding div should be the same as the images width and height, you may also have to adjust the line-height in the css rule slider_container and font-size in the css rule slider
The scroller movement is relative to the slider movement so if the slider is moved to its right stop position the scroller is scrolled to its right stop position.
You can set the width of the scroll_container and the slider_container to suit as the script adjusts accordingly.
<HTML>
<HEAD>
<TITLE>Custom Scrollbar H</TITLE>
<script type="text/javascript">
var moving=false
var leftStopOffset=0
var rightStopOffset=0
function initCSH(){
scrollContainer=document.getElementById("scroll_container")
theScroller=document.getElementById("scroller")
scrollerElements=theScroller.getElementsByTagName("div")
scrollerWidth=0
for(var i=0;i<scrollerElements.length;i++){
scrollerWidth+=scrollerElements[i].offsetWidth
if(document.body.currentStyle){
scrollerWidth+=parseInt(scrollerElements[i].currentStyle.marginLeft)
scrollerWidth+=parseInt(scrollerElements[i].currentStyle.marginRight)
}
else{
scrollerWidth+=parseInt(document.defaultView.getComputedStyle(scrollerElements[i], '').getPropertyValue("margin-left"))
scrollerWidth+=parseInt(document.defaultView.getComputedStyle(scrollerElements[i], '').getPropertyValue("margin-right"))
}
}
theScroller.style.width=scrollerWidth
sliderContainer=document.getElementById("slider_container")
theSlider = document.getElementById("slider")
scrollAmount=theScroller.offsetWidth-scrollContainer.offsetWidth
slideAmount=sliderContainer.offsetWidth-theSlider.offsetWidth-leftStopOffset-rightStopOffset
step=scrollAmount/slideAmount
theSlider.style.left=leftStopOffset
}
function prepCSHSlider() {
moving=true
posX = tempX - theSlider.offsetLeft
}
function moveCSHSlider(e) {
tempX = (!e ? event.clientX : e.clientX)
if(moving == true){
theSlider.style.left = (tempX - posX) + "px"
if(theSlider.offsetLeft<leftStopOffset){
theSlider.style.left=leftStopOffset
}
if(theSlider.offsetLeft+theSlider.offsetWidth>sliderContainer.offsetWidth-rightStopOffset){
theSlider.style.left=sliderContainer.offsetWidth-theSlider.offsetWidth-rightStopOffset
}
scrollerPos=(theSlider.offsetLeft-leftStopOffset)*step
theScroller.style.left= -scrollerPos
}
}
document.onmousemove = moveCSHSlider
document.onmouseup=new Function("moving=false")
// add onload="initCSH()" to the opening body tag
</script>
<style type="text/css">
#scroll_container{
position:relative;
width:800px;
height:200px;
overflow:hidden;
border:1px solid #800000;
}
#scroller{
position:absolute;
left:0px;
top:0px;
}
#scroller div{
width:200px;
float:left;
margin-left:10px;
margin-right:10px;
padding:5px;
text-align:left;
border:1px solid black;
}
#slider_container{
position:relative;
width:400px;
height:14px;
line-height:12px;
text-align:left;
margin-top:20px;
border-top:1px solid #800000;
border-bottom:1px solid #800000;
}
#slider{
position:absolute;
width:68px;
height:14px;
font-size:5px;
background-image:url(scrollbar_handle.gif);
background-color:red;
}
</style>
<!--[if IE]>
<style type="text/css">
#slider_container{
height:16px
}
</style>
<! [endif]-->
</HEAD>
<BODY onload="initCSH()">
<h1><span>Custom Scrollbar H</span></h1>
<DIV id="scroll_container">
<DIV id="scroller">
<div>Add or remove content divs as required</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
</DIV>
</DIV>
<br style="clear:both">
<DIV id="slider_container">
<div id="slider" onmousedown="prepCSHSlider()"></div>
</DIV>
<br style="clear:both">
</BODY>
</HTML>