jquery.fn.setscroll = function(_scroll,_scroll_up,_scroll_down,_scroll_bar){
this.each(function(){
var _bar_margin = 3;
//create scroll dom
var _scroll_control = jquery('
').width(_scroll.width).css({'position':'absolute','float':'none',margin:0,padding:0}).css('background','url('+_scroll.img+')');
var _scroll_control_up = jquery('
').attr('src',_scroll_up.img).width(_scroll.width).css({'z-index':'1000','position':'absolute', 'top':'0','float':'none',margin:0,padding:0});
var _scroll_control_down = jquery('
').attr('src',_scroll_down.img).width(_scroll.width).css({'z-index':'1000','position':'absolute', 'bottom':'0','float':'none',margin:0,padding:0});
var _scroll_control_bar = jquery('
').attr('src',_scroll_bar.img).width(_scroll.width).css({'z-index':'1500','position':'absolute','float':'none',margin:0,padding:0,height:_scroll_bar.height+'px'}).css('top',_scroll_up.height+_bar_margin+'px');
_scroll_control.append(_scroll_control_up);
_scroll_control.append(_scroll_control_bar);
_scroll_control.append(_scroll_control_down);
var _oheight = jquery(this).css('height').substring(0,jquery(this).css('height').indexof('px'));
var _owidth = jquery(this).width();
var _ocontent = jquery(this).html();
if(jquery(this).attr('scrollheight')<=_oheight) return;
var _content_zone = jquery('
').html(_ocontent).css({ width:_owidth-10+'px',height:_oheight+'px',overflow:'hidden','float':'none',margin:0,padding:0});
jquery(this).css({'overflow':'hidden'});
jquery(this).empty().append(_content_zone).css({position:'relative'}).append(_scroll_control.css({left:_owidth-_scroll.width+'px',top:'0',height:_oheight+'px',margin:0,padding:0}));
//register drag event
jquery(this).find('.scroll_bar')
.mousedown(
function(){
jquery(document).mousemove(
function(e){
var _content = _content_zone.get(0);
var lastprogress = _scroll_control_bar.attr('progress');
_scroll_control_bar.attr('progress',e.pagey);
var nowprogress = _scroll_control_bar.css('top');
nowprogress = nowprogress.substring(0,nowprogress.indexof('px'));
nowprogress = number(nowprogress) + number(e.pagey-lastprogress);
var preprogress = nowprogress/(_oheight-_scroll_up.height-_scroll_down.height-_scroll_bar.height-(2*_bar_margin));
_content.scrolltop = ((_content.scrollheight - _content.offsetheight) * preprogress);
if(nowprogress<(_scroll_up.height+_bar_margin) || nowprogress > (_oheight-(_scroll_down.height+_scroll_bar.height+_bar_margin))) return false;
try{_scroll_control_bar.css('top',nowprogress+'px');}catch(e){}
return false;
}
);
return false;
}
)
.mouseout(
function(){
jquery(document).mouseup(
function(){
jquery(document).unbind('mousemove');
}
)
}
)
});
}