jquery: hover button for controlling a div's scrollbar?
i'm having a div with lots of content and a vertical scrollbar. i'd like to replace the scrollbar with an up/down button in order to scroll the开发者_C百科 content on hovering the buttons. any ideas how to do this? thanks
Try scrollTop()
var timeoutId = 0;
function scrollIt(amount){
$('div').scrollTop($('div').scrollTop()+amount);
}
$('.down').mousedown(function() {
timeoutId = setTimeout(scrollIt(5), 1000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeoutId);
});
$('.up').mousedown(function() {
timeoutId = setTimeout(scrollIt(-5), 1000);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeoutId);
});
I think this plugin might be helpful: http://www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html
I think based on this, you'll get a pretty good start on how to do this.
http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12
精彩评论