Menu
I have been searching for quite awhile now and am trying to find a decent, simple image zoom script. When the user’s mouse is over the image, a small box will hover next too the cursor with the zoomed area. I did find the TJPzoom, but the user cannot click to change the zoom because the image is a HUGE image map. Any ideas on where to find something like this?
anyone know of a script that I could possibly use?[/QUOTE]What do you mean by 'click to change the zoom'?
[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>
<style type="text/css">
/*<![CDATA[*/
.frame {
position:absolute;z-Index:2;width:100px;height:100px;border:solid black 1px;
}
/*]]>*/
</style>
<script type="text/javascript">
/*<![CDATA[*/
function zxcPanImage(id,cls,os){
var oop=new zxcPanImageOOP(id,cls,os);
}
function zxcPanImageOOP(id,cls,os){
this.obj=document.getElementById(id);
this.frame=zxcES('DIV',{position:'absolute',visibility:'hidden',overflow:'hidden'},document.body);
this.frame.className=cls;
this.img=zxcES('IMG',{position:'absolute',left:'0px',top:'0px',width:800+'px',height:400+'px'},this.frame);
this.img.src='http://www.vicsjavascripts.org.uk/StdImages/One.gif'
this.img.src=this.obj.src;
this.os=os||5;
this.addevt(this.obj,'mousemove','msemove');
this.addevt(this.obj,'mouseout','hide');
}
zxcPanImageOOP.prototype.msemove=function(e){
var pos=this.pos(this.obj),mse=this.mse(e),fwh=[this.frame.offsetWidth,this.frame.offsetHeight],r=this.img.width/this.obj.width;
zxcES(this.frame,{visibility:'visible',left:(mse[0]<pos[0]+this.obj.width-fwh[0]-this.os?mse[0]+this.os:mse[0]-fwh[0]-this.os)+'px',top:mse[1]+'px',top:(mse[1]>pos[1]+fwh[1]+this.os?mse[1]-fwh[1]-this.os:mse[1]+this.os)+'px'});
zxcES(this.img,{left:Math.min((-mse[0]+pos[0])*r+fwh[0]/2,0)+'px',top:Math.max(Math.min((-mse[1]+pos[1])*r+fwh[1]/2,0),-(this.img.height-fwh[1]))+'px'});
document.Show.Show0.value=[this.img.offsetTop,-(this.img.height-fwh[1])];
}
zxcPanImageOOP.prototype.hide=function(){
zxcES(this.frame,{visibility:'hidden'});
}
zxcPanImageOOP.prototype.pos=function(obj){
var rtn=[obj.offsetLeft,obj.offsetTop];
while(obj.offsetParent!=null){
var objp=obj.offsetParent;
rtn[0]+=objp.offsetLeft-objp.scrollLeft;
rtn[1]+=objp.offsetTop-objp.scrollTop;
obj=objp;
}
return rtn;
}
zxcPanImageOOP.prototype.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); });
else {
var prev=o['on'+t];
if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
else o['on'+t]=o[f];
}
}
zxcPanImageOOP.prototype.mse=function(ev){
if (document.all) return [ev.clientX+zxcDocS()[0],ev.clientY+zxcDocS()[1]];
return [ev.pageX,ev.pageY];
}
function zxcDocS(){
if (!document.body.scrollTop) return [document.documentElement.scrollLeft,document.documentElement.scrollTop];
return [document.body.scrollLeft,document.body.scrollTop];
}
function zxcES(ele,style,par,txt){
if (typeof(ele)=='string') ele=document.createElement(ele);
for (key in style) ele.style[key]=style[key];
if (par) par.appendChild(ele);
if (txt) ele.appendChild(document.createTextNode(txt));
return ele;
}
/*]]>*/
</script>
</head>
<body onload="zxcPanImage('tst','frame');">
<img id="tst" src="http://www.gothics-r-us.com/generatemap.php" width="700" height="350"
style="position:relative;left:100px;"
/>
<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:420px;left:0px;" >
<input size=100 name=Show0 >
<input size=10 name=Show1 >
<input size=10 name=Show2 >
<input size=10 name=Show3 >
<input size=10 name=Show4 >
<input size=10 name=Show5 >
<input size=10 name=Show6 >
<input size=10 name=Show7 >
<input size=10 name=Show8 >
<input size=10 name=Show9 ><br>
<textarea name=TA rows=1 cols=100 ></textarea>
</form>
</body>
</html>[/CODE]
[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>
<style type="text/css">
/*<![CDATA[*/
.frame {
position:absolute;z-Index:2;width:100px;height:100px;border:solid black 1px;
}
.menu {
position:absolute;visibility:hidden;z-Index:3;width:100px;height:92px;border:solid black 1px;background-Color:#FFFFCC;
font-Size:12px;text-Align:center;cursor:pointer;
}
/*]]>*/
</style>
<script type="text/javascript">
/*<![CDATA[*/
// Image Pan (18-April-2009) Draft
// by Vic Phillips http://www.vicsjavascripts.org.uk
// Mousover an image and a frame displaying an enlarged version of the image will be displated
// in a 'frame' adjacent to the mouse position.
// The framed imageg will be centered in the 'frame' at the mouse position.
// An option allows a menu to be displayed on double click to expand or contract the 'frame' or framed image size.
//
// There may be as many applications as required on a page.
// The script is initialised by a BODY or window event call assign the instance of the script to a variable.
// **** The HTML and CSS Code.
//
// The Image must be assigned a unique id name.
// The 'frame' size and border nust be defined by a CSS class.
// If a menu is required an element must be defined inthe HTML code
// and must be assigned a unique id name consisting of the image id+'menu'.
// The outline of the menu must be defined by CSS or inline style.
// Note:
// The frame and menu must not have a style display of 'none'.
//
// **** Initalising the Script.
//
// The script is initialised by a BODY or window event call assign the instance of the script to a variable.
// e.g.
// var oop=new zxcImagePan('tst','frame',5,2);
// where:
// parameter 0 = the unique ID name of the image. (string)
// parameter 1 = the class name of the 'frame'. (string)
// parameter 2 = (optional) the offset of the 'frame' from the mouse position'. (digits, default = 5)
// parameter 3 = (optional) the initial magnification of the framed image. (digits, default = 5)
// parameter 4 = (optional) the src of the framed image. (string, default = the src of the main image)
//
// ****** Functional Code(4.02K) - NO NEED to Change.
function zxcImagePan(id,cls,os,mag,src){
mag=mag||1;
this.os=os||5;
this.obj=document.getElementById(id);
this.frame=this.es('DIV',{position:'absolute',visibility:'hidden',overflow:'hidden'},document.body);
this.frame.className=cls;
this.img=this.es('IMG',{position:'absolute'},this.frame);
this.img.src=src||this.obj.src;
this.es(this.img,{width:(!src?this.obj.width:this.img.width)*mag+'px',height:(!src?this.obj.height:this.img.height)*mag+'px'});
this.addevt(document,'mousemove','msemove');
this.menu=document.getElementById(id+'menu');
if (this.menu){
this.es(this.menu,{position:'absolute',visibility:'hidden',overflow:'hidden'});
this.addevt(this.obj,'dblclick','menuopen');
var items=['Close','Imgage +ve','Imgage -ve','Frame +ve','Frame -ve']
for (var item,z0=0;z0<items.length;z0++){
item=this.es('DIV',{height:this.menu.offsetHeight/5+'px',borderBottom:'solid black 1px'},this.menu,items[z0]);
this.addevt(item,'click','menuselect',z0);
}
this.es(this.menu,{height:item.offsetTop+item.offsetHeight+'px'});
this.fmin=[this.frame.offsetWidth,this.frame.offsetHeight];
this.imin=[this.img.width,this.img.height];
}
}
zxcImagePan.prototype.msemove=function(e){
this.es(this.frame,{visibility:'hidden'});
var pos=this.pos(this.obj),mse=this.mse(e),owh=[this.obj.width,this.obj.height];
if (mse[0]>pos[0]-this.os&&mse[0]<pos[0]+owh[0]+this.os&&mse[1]>pos[1]-this.os&&mse[1]<pos[1]+owh[1]+this.os){
var fwh=[this.frame.offsetWidth,this.frame.offsetHeight],r=this.img.width/owh[0];
this.es(this.frame,{visibility:'visible',left:(mse[0]<pos[0]+owh[0]-fwh[0]-this.os?mse[0]+this.os:mse[0]-fwh[0]-this.os)+'px',top:mse[1]+'px',top:(mse[1]>pos[1]+fwh[1]+this.os?mse[1]-fwh[1]-this.os:mse[1]+this.os)+'px'});
this.es(this.img,{left:Math.max(Math.min((-mse[0]+pos[0])*r+fwh[0]/2,0),-(this.img.width-fwh[0]))+'px',top:Math.max(Math.min((-mse[1]+pos[1])*r+fwh[1]/2,0),-(this.img.height-fwh[1]))+'px'});
}
}
zxcImagePan.prototype.menuopen=function(e){
var mse=this.mse(e)
this.es(this.menu,{visibility:'visible',left:mse[0]-this.menu.offsetWidth/2+'px',top:mse[1]-this.menu.offsetHeight/2+'px'});
return false;
}
zxcImagePan.prototype.menuselect=function(e,nu){
var iwh=[this.img.width,this.img.height],fwh=[this.frame.offsetWidth,this.frame.offsetHeight];
if (nu==0) this.es(this.menu,{visibility:'hidden'});
if (nu==1) this.es(this.img,{width:iwh[0]*1.1+'px',height:iwh[1]*1.1+'px'});
if (nu==2) this.es(this.img,{width:Math.max(iwh[0]/1.1,this.imin[0])+'px',height:Math.max(iwh[1]/1.1,this.imin[1])+'px'});
if (nu==3) this.es(this.frame,{width:fwh[0]*1.1+'px',height:fwh[1]*1.1+'px'});
if (nu==4) this.es(this.frame,{width:Math.max(fwh[0]/1.1,this.fmin[0])+'px',height:Math.max(fwh[1]/1.1,this.fmin[1])+'px'});
this.msemove(e);
}
zxcImagePan.prototype.pos=function(obj){
var rtn=[obj.offsetLeft,obj.offsetTop];
while(obj.offsetParent!=null){
var objp=obj.offsetParent;
rtn[0]+=objp.offsetLeft-objp.scrollLeft;
rtn[1]+=objp.offsetTop-objp.scrollTop;
obj=objp;
}
return rtn;
}
zxcImagePan.prototype.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); });
else {
var prev=o['on'+t];
if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
else o['on'+t]=o[f];
}
}
zxcImagePan.prototype.mse=function(ev){
if (document.all) return [ev.clientX+this.docs()[0],ev.clientY+this.docs()[1]];
return [ev.pageX,ev.pageY];
}
zxcImagePan.prototype.docs=function(){
if (!document.body.scrollTop) return [document.documentElement.scrollLeft,document.documentElement.scrollTop];
return [document.body.scrollLeft,document.body.scrollTop];
}
zxcImagePan.prototype.es=function(ele,style,par,txt){
if (typeof(ele)=='string') ele=document.createElement(ele);
for (key in style) ele.style[key]=style[key];
if (par) par.appendChild(ele);
if (txt) ele.appendChild(document.createTextNode(txt));
return ele;
}
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
function Init(){
var oop=new zxcImagePan('tst','frame',5,2);
}
/*]]>*/
</script>
</head>
<body onload="Init();">
<img id="tst" src="http://www.gothics-r-us.com/generatemap.php" width="700" height="350" title="Double Click for Menu" alt="World"
style="position:relative;left:100px;top:50px;"
/>
<div id="tstmenu" class="menu" ></div>
</body>
</html>[/CODE]
[CODE]zxcImagePan.prototype.pos=function(obj){
var rtn=[obj.offsetLeft,obj.offsetTop];
while(obj.offsetParent!=null){
var objp=obj.offsetParent;
rtn[0]+=objp.offsetLeft;
rtn[1]+=objp.offsetTop;
obj=objp;
}
return rtn;
}
[/CODE]
0.1.9 — BETA 5.8