1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;
var mouseX, mouseY, enterX, enterY;
function addEvent(event,method)
{
this[event] = method;
if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function removeEvent(event)
{
this[event] = null;
if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name)
{
var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval("document."+name) : false;
if ( el == null ) return null;
el.css = ns4 ? el : el.style;
el.getTop = function(){return parseInt(el.css.top) || 0};
el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
el.getLeft = function(){return parseInt(el.css.left) || 0};
el.setLeft = function(x){el.css.left = ns4 ? x: x+"px"};
el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
el.getWidth = function(){return ns4 ? el.document.width : el.offsetWidth};
el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
el.hideVis = function(){el.css.visibility="hidden"};
el.showVis = function(){el.css.visibility="visible"};
el.addEvent = addEvent;
el.removeEvent = removeEvent;
return el;
}
function getYMouse(e)
{
return iex ? event.clientY : e.pageY;
}
document.addEvent = addEvent;
document.removeEvent = removeEvent;
ScrollObj = function(speed, groupName)
{
this.speed = speed;
this.trackObj = getElement(groupName+"ScrollTrack");
this.dragObj = getElement(groupName+"ScrollThumb");
this.contentMaskObj = getElement(groupName+"ContentClip");
this.contentObj = getElement(groupName+"Content");
this.obj = groupName+"ContentObject";
eval(this.obj+"=this");
this.dragHeight = this.dragObj.getHeight()-2 - (iex ? 4 : 0);
this.trackHeight = getElement(groupName+"ScrollThumbTrack").getHeight();
this.trackTop = this.trackObj.getTop();
this.trackLength = this.trackHeight-this.dragHeight;
this.trackBottom = this.trackTop+this.trackLength;
this.contentMaskHeight = this.contentMaskObj.getClipHeight();
this.contentHeight = this.contentObj.getHeight();
this.contentLength = this.contentHeight-this.contentMaskHeight;
this.scrollLength = this.trackLength/this.contentLength;
this.scrollTimer = null;
if (this.contentHeight <= this.contentMaskHeight) {
this.dragObj.hideVis();
} else {
var self = this;
this.dragObj.addEvent("onmousedown", function(e){self.startDrag(e);return false});
if(iex) this.dragObj.addEvent("ondragstart", function(){return false});
this.dragObj.showVis();
}
}
ScrollObj.prototype.startDrag = function(e)
{
this.dragStartMouse = getYMouse(e);
this.dragStartOffset = this.dragObj.getTop();
var self = this;
document.removeEvent("onmousemove");
document.addEvent("onmousemove", function(e){self.drag(e)});
document.addEvent("onmouseup", function(){self.stopDrag()});
}
ScrollObj.prototype.stopDrag = function()
{
document.removeEvent("onmousemove");
document.addEvent("onmousemove", getYMouse);
document.removeEvent("onmouseup");
}
ScrollObj.prototype.drag = function(e)
{
var currentMouse = getYMouse(e);
var mouseDifference = currentMouse-this.dragStartMouse;
var dragDistance = this.dragStartOffset+mouseDifference;
var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
this.dragObj.setTop(dragMovement);
var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
this.contentObj.setTop(contentMovement);
}
ScrollObj.prototype.scroll = function(speed)
{
var contentMovement = this.contentObj.getTop()+speed;
var dragMovement = this.trackTop-Math.round(this.contentObj.getTop()*(this.trackLength/this.contentLength));
if(contentMovement > 0){
contentMovement = 0;
}else if(contentMovement < -this.contentLength){
contentMovement = -this.contentLength;
}
if ( dragMovement < this.trackTop ) {
dragMovement = this.trackTop;
} else if ( dragMovement > this.trackBottom ) {
dragMovement = this.trackBottom;
}
this.contentObj.setTop(contentMovement);
this.dragObj.setTop(dragMovement);
this.scrollTimer = window.setTimeout(this.obj+".scroll("+speed+")",25);
} |
Partager