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>
<div id="p1" style="position:relative;width:400px;height:300px;border:solid red 1px;" >
<img src='http://www.ezilon.com/maps/images/world-physical-map.gif' style="width:300%;">
</div>
<script type="text/javascript">
/*<![CDATA[*/
var zxcPan={
init:function(id){
var p=document.getElementById(id),img=p.getElementsByTagName('IMG')[0],obj;
p.style.overflow='hidden';
img.style.position='absolute';
obj={
p:p,
img:img
}
this.addevt(p,'mousemove','pan',obj);
this.addevt(p,'mouseup','rtrn',obj);
},
rtrn:function(e,obj){
alert('image x = '+obj.img.style.left+'\nimage y = '+obj.img.style.top);
alert('mouse position = '+obj.xy);
},
pan:function(e,obj){
var m=this.mse(e),p=this.pos(obj.p),x=m[0]-p[0],y=m[1]-p[1];
obj.img.style.left=-x/(obj.p.offsetWidth/(obj.img.width-obj.p.offsetWidth))+'px';
obj.img.style.top=-y/(obj.p.offsetHeight/(obj.img.height-obj.p.offsetHeight))+'px';
obj.xy=[x,y];
},
pos:function(obj){
var rtn=[0,0];
while(obj){
rtn[0]+=obj.offsetLeft;
rtn[1]+=obj.offsetTop;
obj=obj.offsetParent;
}
return rtn;
},
mse:function(e){
if (window.event){
var docs=[document.body.scrollLeft,document.body.scrollTop];
if (!document.body.scrollTop){
docs=[document.documentElement.scrollLeft,document.documentElement.scrollTop];
}
return [e.clientX+docs[0],e.clientY+docs[1]];
}
return [e.pageX,e.pageY];
},
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); });
}
}
zxcPan.init('p1');
/*]]>*/
</script>
</body>
</html>
Bookmarks