I am attempting to replace the browser's native scroll-bar using the rangeinput function of JqueryTools.
Here is the example page: http://conceptionkit.co.uk/ck/support
The page has multiple scrollable divs with the following html structure:
<div class="scrollwrap"><!-- scrollwrap doesn't move and has overflow:hidden -->
<div class="scroll"><!- this is the scrollable pane --></div>
<!-- this is the rangecontrol that is converted into a
vertical scrollbar by the script -->
<input class="hide" type="range" max="300" step="1" />
</div>
For a single instance on the page the following code works:
var scroll = jQuery(".scroll");
// initialize rangeinput
jQuery(":range").rangeinput({
// slide the DIV along with the range using jQuery css() method
onSlide: function(ev, step) { scroll.css({bottom: -step});},
// display progressbar
progress: true,
// initial value. also sets the DIV initial scroll position
value: 100,
// this is called when the slider is clicked. we animate the DIV
change: function(e, i) { scroll.animate({bottom: -i}, "fast");},
// disable drag handle animation when when slider is clicked
speed: 0
});
However, when I try to generalize the script, it doesn't work. I think the problem is having multiple instances of the variable named "scroll". Maybe they are conflicting?
Here is my attempt at a script to put scrollbars on all the scrollwrap instances on the page. Since I have to correlate each rangeinput to the correct pane, it iterates over the jQuery(".scrollwrap").each() and finds the scroll pane and the range control in each one:
// default style for .scroll is overflow:auto for no-js browsers.
// must turn that off first
jQuery(".scroll").css('overflow','hidden');
jQuery(".scrollwrap").css('overflow','hidden').each(function(index){
// Inject range control element
jQuery(this).append('<input class="hide" type="range" max="300" step="1" />');
var scroll = jQuery(".scroll",this);
// initialize rangeinput
jQuery(":range", this).rangeinput({
// slide the DIV along with the range using jQuery css() method
onSlide: function(ev, step) { scroll.css({top: -step});},
// display progressbar
progress: true,
// initial value. also sets the DIV initial scroll position
value: 100,
// this is called when the slider is clicked. we animate the DIV
change: function(e, i) { scroll.animate({top: -i}, "fast");},
// disable drag handle animation when when slider is clicked
speed: 0
});
});
The script above doesn't generate any errors, it does create the slider control, but moving the slide does not move the related .scroll div.
What am I doing wrong here?