Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
Mousedown and Drag
<img src="http://www.vicsjavascripts.org.uk/StdImages/WinterPalace.jpg" width="1404" />
<script type="text/javascript">
/*<![CDATA[*/
function zxcWS(){
if (window.innerHeight) return [window.pageXOffset,window.pageYOffset];
else if (document.documentElement.clientHeight) return [document.documentElement.scrollLeft,document.documentElement.scrollTop];
return [document.body.scrollLeft,document.body.scrollTop];
}
function zxcScroll(){
this.addevt(document,'mousedown','mse');
this.addevt(document,'mouseup','mse');
this.addevt(document,'mousemove','msemove');
}
zxcScroll.prototype={
mse:function(e){
this.drag=e.type=='mousedown';
this.sx=zxcWS()[0];
this.sy=zxcWS()[1];
this.mx=e.clientX;
this.my=e.clientY
if (e.preventDefault){
e.preventDefault();
}
return false;
},
msemove:function(e){
if (this.drag==true){
var mx=e.clientX,my=e.clientY
window.scrollTo(this.sx-e.clientX+this.mx,this.sy-e.clientY+this.my);
if (e.preventDefault){
e.preventDefault();
}
return false;
}
},
addevt:function(o,t,f,p){
var oop=this;
if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
}
}
new zxcScroll();
/*]]>*/
</script></body>
</html>
Bookmarks