/* outermost element for the scroller (stays still) */
* {
box-sizing: border-box;
}
#scrollwrap {
position:relative;
overflow:hidden;
width: 450px;
height:150px;
border:1px solid #000;
margin-bottom:15px;
}
/* the element that moves forward/backward */
#scroll {
position:absolute;
white-space: nowrap;
}
#scroll li {
padding:20px;
border: 1px red solid;
font:bold 30px sans-serif;
height:50px;
color:#fff;
text-shadow:1px 2px 2px #000;
width: 100px;
display: inline-block;
}
.slider {
position:relative;
cursor:pointer;
height:1px;
border:2px solid #00118E;
width:450px;
-moz-border-radius:2px;
-webkit-border-radius:2px;
}
.progress {
background-color:#00118E;
height:3px;
position:absolute;
width:0;
}
.handle {
border:1px solid #cfcfcf;
background-color:#fff;
height:20px;
width:80px;
position:absolute;
top:-12px;
display:block;
cursor:move;
-moz-border-radius:14px;
-webkit-border-radius:14px;
}
.handle:active {
background:blue;
}
.range {
display:none;
}
/* get rid of those system borders being generated for A tags */
a:active {
outline:none;
}
:focus {
-moz-outline-style:none;
}
body {
margin:20px;
}
JavaScript
// get handle to the scrollable DIV
var scroll = $("#scroll");
// initialize rangeinput
$(":range").rangeinput({
// slide the DIV along with the range using jQuery's css() method
onSlide: function (ev, step) {
scroll.css({
left: -step
});
},
// display progressbar
progress: false,
// initial value. also sets the DIV's initial scroll position
value: 1,
// this is called when the slider is clicked. we animate the DIV
change: function (e, i) {
scroll.animate({
left: -i
}, "fast");
},
// disable drag handle animation when when slider is clicked
speed: 0
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.