/**
*
* copyright (c) 2009 may(qq104010230)
* http://www.winwill.com
* http://www.winwill.com/jquery/jscroll.html
* admin@winwill.com
*/
/*--------------------------------------------------------------------------------------------------*/
$j.fn.extend({//添加滚轮事件//by jun
mousewheel: function (func) {
return this.each(function () {
var _self = this;
_self.d = 0;//滚动方向
if ($j.browser.msie || $j.browser.safari) {
_self.onmousewheel = function () { _self.d = event.wheeldelta; event.returnvalue = false; func && func.call(_self); };
} else {
_self.addeventlistener("dommousescroll", function (e) {
_self.d = e.detail > 0 ? -1 : 1;
e.preventdefault();
func && func.call(_self);
}, false);
}
});
}
});
$j.fn.extend({
jscroll: function (j) {
return this.each(function () {
j = j || {}
j.bar = j.bar || {};//2级对象
j.btn = j.btn || {};//2级对象
j.bar.bg = j.bar.bg || {};//3级对象
j.bar.bd = j.bar.bd || {};//3级对象
j.btn.ubg = j.btn.ubg || {};//3级对象
j.btn.dbg = j.btn.dbg || {};//3级对象
var jun = {
w: "15px"
, bgurl: ""
, bg: "rgba(230, 230, 230, 1 )"
, bar: {
pos: "up"
, bd: { out: "#b5b5b5", hover: "#ccc" }
, bg: { out: "#bebebe", hover: "#fff", focus: "orange" }
}
, btn: {
btn: true
, ubg: { out: "#ccc", hover: "#fff", focus: "orange" }
, dbg: { out: "#ccc", hover: "#fff", focus: "orange" }
}
, fn: function () { }
}
j.w = j.w || jun.w;
j.bgurl = j.bgurl || jun.bgurl;
j.bg = j.bg || jun.bg;
j.bar.pos = j.bar.pos || jun.bar.pos;
j.bar.bd.out = j.bar.bd.out || jun.bar.bd.out;
j.bar.bd.hover = j.bar.bd.hover || jun.bar.bd.hover;
j.bar.bg.out = j.bar.bg.out || jun.bar.bg.out;
j.bar.bg.hover = j.bar.bg.hover || jun.bar.bg.hover;
j.bar.bg.focus = j.bar.bg.focus || jun.bar.bg.focus;
j.btn.btn = j.btn.btn != undefined ? j.btn.btn : jun.btn.btn;
j.btn.ubg.out = j.btn.ubg.out || jun.btn.ubg.out;
j.btn.ubg.hover = j.btn.ubg.hover || jun.btn.ubg.hover;
j.btn.ubg.focus = j.btn.ubg.focus || jun.btn.ubg.focus;
j.btn.dbg.out = j.btn.dbg.out || jun.btn.dbg.out;
j.btn.dbg.hover = j.btn.dbg.hover || jun.btn.dbg.hover;
j.btn.dbg.focus = j.btn.dbg.focus || jun.btn.dbg.focus;
j.fn = j.fn || jun.fn;
var _self = this;
var stime, sp = 0, isup = 0;
$j(_self).css({ overflow: "hidden", position: "absolute", padding: "1px" });
var dw = $j(_self).width(), dh = $j(_self).height() - 1;
var sw = j.w ? parseint(j.w) : 21;
var sl = dw - sw
var bw = j.btn.btn == true ? sw : 0;
if ($j(_self).children(".jscroll-c").height() == null) {//存在性检测
$j(_self).wrapinner("
");
$j(_self).children(".jscroll-c").prepend("");
$j(_self).append("");
}
var jscrollc = $j(_self).children(".jscroll-c");
var jscrolle = $j(_self).children(".jscroll-e");
var jscrollh = jscrolle.children(".jscroll-h");
var jscrollu = jscrolle.children(".jscroll-u");
var jscrolld = jscrolle.children(".jscroll-d");
if ($j.browser.msie) { document.execcommand("backgroundimagecache", false, true); }
jscrollc.css({ "padding-right": sw });
jscrolle.css({ width: sw, background: j.bg, "background-image": j.bgurl });
jscrollh.css({ top: bw, background: j.bar.bg.out, "background-image": j.bgurl, "border-color": j.bar.bd.out, width: "4px", marginleft: "-2px", borderradius: "19px" });
jscrollu.css({ height: bw, background:j.bg, "background-image": j.bgurl });
jscrolld.css({ height: bw, background: j.btn.dbg.out, "background-image": j.bgurl });
jscrollh.hover(function () { if (isup == 0) $j(this).css({ background: j.bar.bg.hover, "background-image": j.bgurl, "border-color": j.bar.bd.hover }) }, function () { if (isup == 0) $j(this).css({ background: j.bar.bg.out, "background-image": j.bgurl, "border-color": j.bar.bd.out }) })
jscrollu.hover(function () { if (isup == 0) $j(this).css({ background: j.btn.ubg.hover, "background-image": j.bgurl }) }, function () { if (isup == 0) $j(this).css({ background: j.btn.ubg.out, "background-image": j.bgurl }) })
jscrolld.hover(function () { if (isup == 0) $j(this).css({ background: j.btn.dbg.hover, "background-image": j.bgurl }) }, function () { if (isup == 0) $j(this).css({ background: j.btn.dbg.out, "background-image": j.bgurl }) })
var sch = jscrollc.height();
//var sh = math.pow(dh,2) / sch ;//math.pow(x,y)x的y次方
var sh = (dh - 2 * bw) * dh / sch
if (sh < 10) { sh = 10 }
var wh = sh / 6//滚动时候跳动幅度
// sh = parseint(sh);
var curt = 0, allows = false;
jscrollh.height(sh);
if (sch <= dh) { jscrollc.css({ padding: 0 }); jscrolle.css({ display: "none" }) } else { allows = true; }
if (j.bar.pos != "up") {
curt = dh - sh - bw;
sett();
}
jscrollh.bind("mousedown", function (e) {
j['fn'] && j['fn'].call(_self);
isup = 1;
jscrollh.css({ background: j.bar.bg.focus, "background-image": j.bgurl })
var pagey = e.pagey, t = parseint($j(this).css("top"));
$j(document).mousemove(function (e2) {
curt = t + e2.pagey - pagey;//pagey浏览器可视区域鼠标位置,screeny屏幕可视区域鼠标位置
sett();
});
$j(document).mouseup(function () {
isup = 0;
jscrollh.css({ background: j.bar.bg.out, "background-image": j.bgurl, "border-color": j.bar.bd.out })
$j(document).unbind();
});
return false;
});
jscrollu.bind("mousedown", function (e) {
j['fn'] && j['fn'].call(_self);
isup = 1;
jscrollu.css({ background: j.btn.ubg.focus, "background-image": j.bgurl })
_self.timesett("u");
$j(document).mouseup(function () {
isup = 0;
jscrollu.css({ background: j.btn.ubg.out, "background-image": j.bgurl })
$j(document).unbind();
cleartimeout(stime);
sp = 0;
});
return false;
});
jscrolld.bind("mousedown", function (e) {
j['fn'] && j['fn'].call(_self);
isup = 1;
jscrolld.css({ background: j.btn.dbg.focus, "background-image": j.bgurl })
_self.timesett("d");
$j(document).mouseup(function () {
isup = 0;
jscrolld.css({ background: j.btn.dbg.out, "background-image": j.bgurl })
$j(document).unbind();
cleartimeout(stime);
sp = 0;
});
return false;
});
_self.timesett = function (d) {
var self = this;
if (d == "u") { curt -= wh; } else { curt += wh; }
sett();
sp += 2;
var t = 500 - sp * 50;
if (t <= 0) { t = 0 };
stime = settimeout(function () { self.timesett(d); }, t);
}
jscrolle.bind("mousedown", function (e) {
j['fn'] && j['fn'].call(_self);
curt = curt + e.pagey - jscrollh.offset().top - sh / 2;
asett();
return false;
});
function asett() {
if (curt < bw) { curt = bw; }
if (curt > dh - sh - bw) { curt = dh - sh - bw; }
jscrollh.stop().animate({ top: curt }, 100);
var sct = -((curt - bw) * sch / (dh - 2 * bw));
jscrollc.stop().animate({ top: sct }, 1000);
};
function sett() {
if (curt < bw) { curt = bw; }
if (curt > dh - sh - bw) { curt = dh - sh - bw; }
jscrollh.css({ top: curt });
var sct = -((curt - bw) * sch / (dh - 2 * bw));
jscrollc.css({ top: sct });
};
$j(_self).mousewheel(function () {
if (allows != true) return;
j['fn'] && j['fn'].call(_self);
if (this.d > 0) { curt -= wh; } else { curt += wh; };
sett();
})
});
}
});