var isIE = (document.all) ? true : false;
var $$ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() { this.initialize.apply(this, arguments); }
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args);
}
}
var BindAsEventListener = function(object, fun) {
return function(event) {
return fun.call(object, Event(event));
}
}
function Event(e){
var oEvent = isIE ? window.event : e;
if (isIE) {
oEvent.pageX = oEvent.clientX + document.documentElement.scrollLeft;
oEvent.pageY = oEvent.clientY + document.documentElement.scrollTop;
oEvent.preventDefault = function () { this.returnValue = false; };
oEvent.detail = oEvent.wheelDelta / (-40);
oEvent.stopPropagation = function(){ this.cancelBubble = true; };
}
return oEvent;
}
var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
var CurrentStyle = function(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}
function addEventHandler(oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
function removeEventHandler(oTarget, sEventType, fnHandler) {
if (oTarget.removeEventListener) {
oTarget.removeEventListener(sEventType, fnHandler, false);
} else if (oTarget.detachEvent) {
oTarget.detachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = null;
}
};
var Slider = Class.create();
Slider.prototype = {
initialize: function(container, bar, options) {
this.Bar = $$(bar);
this.Container = $$(container);
this._timer = null;
this._ondrag = false;
this._IsMin = this._IsMax = this._IsMid = false;
this._drag = new Drag(this.Bar, { Limit: true, mxContainer: this.Container,
onStart: Bind(this, this.DragStart), onStop: Bind(this, this.DragStop), onMove: Bind(this, this.Move)
});
this.SetOptions(options);
this.WheelSpeed = Math.max(0, this.options.WheelSpeed);
this.KeySpeed = Math.max(0, this.options.KeySpeed);
this.MinValue = this.options.MinValue;
this.MaxValue = this.options.MaxValue;
this.RunTime = Math.max(1, this.options.RunTime);
this.RunStep = Math.max(1, this.options.RunStep);
this.Ease = !!this.options.Ease;
this.EaseStep = Math.max(1, this.options.EaseStep);
this.onMin = this.options.onMin;
this.onMax = this.options.onMax;
this.onMid = this.options.onMid;
this.onDragStart = this.options.onDragStart;
this.onDragStop = this.options.onDragStop;
this.onMove = this.options.onMove;
this._horizontal = !!this.options.Horizontal;//一般不允许修改
//锁定拖放方向
this._drag[this._horizontal ? "LockY" : "LockX"] = true;
//点击控制
addEventHandler(this.Container, "click", BindAsEventListener(this, function(e){ this._ondrag || this.ClickCtrl(e);}));
//取消冒泡,防止跟Container的click冲突
addEventHandler(this.Bar, "click", BindAsEventListener(this, function(e){ e.stopPropagation(); }));
//设置鼠标滚轮控制
this.WheelBind(this.Container);
//设置方向键控制
this.KeyBind(this.Container);
//修正获取焦点
var oFocus = isIE ? (this.KeyBind(this.Bar), this.Bar) : this.Container;
addEventHandler(this.Bar, "mousedown", function(){ oFocus.focus(); });
//ie鼠标捕获和ff的取消默认动作都不能获得焦点,所以要手动获取
//如果ie把focus设置到Container,那么在出现滚动条时ie的focus可能会导致自动滚屏
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
MinValue: 0,//最小值
MaxValue: 100,//最大值
WheelSpeed: 5,//鼠标滚轮速度,越大越快(0则取消鼠标滚轮控制)
KeySpeed: 50,//方向键滚动速度,越大越慢(0则取消方向键控制)
Horizontal: true,//是否水平滑动
RunTime: 20,//自动滑移的延时时间,越大越慢
RunStep: 2,//自动滑移每次滑动的百分比
Ease: false,//是否缓动
EaseStep: 5,//缓动等级,越大越慢
onMin: function(){},//最小值时执行
onMax: function(){},//最大值时执行
onMid: function(){},//中间值时执行
onDragStart:function(){},//拖动开始时执行
onDragStop: function(){},//拖动结束时执行
onMove: function(){}//滑动时执行
};
Extend(this.options, options || {});
},
--这个是滚动条的JS代码。
麻烦各位高手看看,有什么解决办法? 因为BT美工要求做图片背景的滚动条。所以只能用到重写滚动条了。