menu CSS
Code:
.popitmenu{
position: absolute;
background-color: white;
border:1px solid black;
font: normal 12px Verdana;
line-height: 18px;
z-index: 100;
visibility: hidden;
}
.popitmenu a{
text-decoration: none;
padding-left: 6px;
color: black;
display: block;
}
.popitmenu a:hover{ /*hover background color*/
background-color: #CCFF9D;
}
sample HTML
Code:
<!-- This is 'product_linkover' -->
<div id="Layer-19" onMouseover="M.Show(this,0,0,20);" onMouseout="M.Hide();" >
<a href="product.html"><img src="images/Layer-19.png" width="112" height="36" alt="product" border="0" onMouseover="" onMouseout=""/></a></div>
<!-- This is 'partners_linkover' -->
<div id="Layer-17" onMouseover="M.Show(this,1,0,20);" onMouseout="M.Hide();" >
<a href="partners.html"><img src="images/Layer-17.png" width="112" height="36" alt="partners" class="pngimg" border="0" /></a></div>
menu script
Code:
var menu=[]
menu[0]=[];
// field [0][0] = the class name of the menu.
// field [0][1] = (optional) the menu width.
// field [0][2] = (optional) the menu height.
menu[0][0]=['popitmenu',150,60];
// field [n][0] = the menu item text.
// field [n][1] = the menu item href.
// field [n][2] = (optional) the menu height.
menu[0][1]=['The Company','The_Company.html'];
menu[0][2]=['Management Team','The_ManaTeam.html'];
menu[0][3]=['Facilities','Facilities.html'];
menu[1]=[];
menu[1][0]=['popitmenu'];
menu[1][1]=['Electric Power Generation (EPG)','EPG.html'];
menu[1][2]=['Public Sector','Public_Sect.html'];
menu[1][3]=['Product Support','Pro_Support.html'];
menu[1][4]=['Fabrication','Fabrication.html'];
menu[1][5]=['Marine','Marine.html'];
function MenuPop(o){
var menus=[],ary=o.MenuArray,oop=this;
for (var z0=0;z0<ary.length;z0++){
menus[z0]=zxcES('DIV',{},document.body);
menus[z0].className=ary[z0][0][0];
zxcES(menus[z0],{left:200*z0+'px'});
if (ary[z0][0][1]){
zxcES(menus[z0],{width:ary[z0][0][1]+'px'});
}
if (ary[z0][0][2]){
zxcES(menus[z0],{height:ary[z0][0][2]+'px'});
}
for (var a,z0a=1;z0a<ary[z0].length;z0a++){
a=zxcES('A',{},menus[z0],ary[z0][z0a][0]);
if (ary[z0][z0a][1]){
a.href=ary[z0][z0a][1];
}
}
}
this.menus=[];
for (var z1=0;z1<menus.length;z1++){
this.menus[z1]=[menus[z1],menus[z1].offsetHeight];
zxcES(menus[z1],{overflow:'hidden'});
menus[z1].onmouseover=function(){ clearTimeout(oop.to); }
menus[z1].onmouseout=function(){ oop.Hide(); }
}
this.oop=new zxcAnimate('height',menus[0],0);
this.ms=o.EffectDuration||500;
this.to=null;
}
MenuPop.prototype={
Show:function(obj,nu,xos,yos){
this.oop.obj.style.visibility='hidden';
if (this.menus[nu]){
this.oop.obj=this.menus[nu][0];
this.oop.animate(0,this.menus[nu][1],this.ms);
var pos=zxcPos(obj);
this.oop.obj.style.visibility='visible';
zxcES(this.oop.obj,{visibility:'visible',left:pos[0]+(xos||0)+'px',top:pos[1]+(yos||0)+'px'});
}
},
Hide:function(){
var oop=this;
this.to=setTimeout(function(){ zxcES(oop.oop.obj,{visibility:'hidden'}); },100);
}
}
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;
}
function zxcPos(obj){
var rtn=[0,0];
while(obj){
rtn[0]+=obj.offsetLeft;
rtn[1]+=obj.offsetTop;
obj=obj.offsetParent;
}
return rtn;
}
the animator
Code:
// Animate (11-January-2010)
// by Vic Phillips http://www.vicsjavascripts.org.uk
// To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.
// With the ability to scale the effect time on specified minimum/maximum values
// and with three types of progression 'sin' and 'cos' and liner.
// **** Application Notes
// **** The HTML Code
//
// when moving an element the inline or class rule style position of the element should be assigned as
// 'position:relative;' or 'position:absolute;'
//
// The element would normally be assigned a unique ID name.
//
// **** Initialising the Script.
//
// The script is initialised by assigning an instance of the script to a variable.
// e.g A = new zxcAnimate('left','id1')
// where:
// A = a global variable (variable)
// parameter 0 = the mode(see Note 1). (string)
// parameter 1 = the unique ID name or element object. (string or element object)
// parameter 1 = the initial value. (digits, default = 0)
// **** Executing the Effect
//
// The effect is executed by an event call to function 'A.animate(10,800 ,5000,[10,800]);'
// where:
// A = the global referencing the script instance. (variable)
// parameter 0 = the start value. (digits, for opacity minimum 0, maximum 100)
// parameter 1 = the finish value. (digits, for opacity minimum 0, maximum 100)
// parameter 2 = period of time between the start and finish of the effect in milliseconds. (digits or defaults to previous or 0(on first call) milliSeconds)
// parameter 3 = (optional) to scale the effect time on a specified minimum/maximum. (array, see Note 3)
// field 0 the minimum value. (digits)
// field 1 the maximum value. (digits)
// parameter 3 = (optional) the type of progression, 'sin', 'cos' or 'liner'. (string, default = 'liner')
// 'sin' progression starts fast and ends slow.
// 'cos' progression starts slow and ends fast.
//
// Note 1: Examples modes: 'left', 'top', 'width', 'height', 'opacity.
// Note 2: The default units(excepting opacity) are 'px'.
// For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
// Note 3: The scale is of particular use when re-calling the effect
// in mid progression to retain an constant rate of progression.
// Note 4: The current effect value is recorded in A.data[0].
// Note 5: A function may be called on completion of the effect by assigning the function
// to the animator intance property .Complete.
// e.g. [instance].Complete=function(){ alert(this.data[0]); };
//
// **** Functional Code(1.58K) - NO NEED to Change
function zxcAnimate(mde,obj,srt){
this.to=null;
this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
this.mde=mde.replace(/\W/g,'');
this.data=[srt||0];
return this;
}
zxcAnimate.prototype.animate=function(srt,fin,ms,scale,c){
clearTimeout(this.to);
this.time=ms||this.time||0;
this.neg=srt<0||fin<0;
this.data=[srt,srt,fin];
this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
this.inc=Math.PI/(2*this.mS);
this.srttime=new Date().getTime();
this.cng();
}
zxcAnimate.prototype.cng=function(){
var oop=this,ms=new Date().getTime()-this.srttime;
this.data[0]=(this.c=='s')?(this.data[2]-this.data[1])*Math.sin(this.inc*ms)+this.data[1]:(this.c=='c')?this.data[2]-(this.data[2]-this.data[1])*Math.cos(this.inc*ms):(this.data[2]-this.data[1])/this.mS*ms+this.data[1];
this.apply();
if (ms<this.mS) this.to=setTimeout(function(){oop.cng()},10);
else {
this.data[0]=this.data[2];
this.apply();
if (this.Complete) this.Complete(this);
}
}
zxcAnimate.prototype.apply=function(){
if (isFinite(this.data[0])){
if (this.data[0]<0&&!this.neg) this.data[0]=0;
if (this.mde!='opacity') this.obj.style[this.mde]=Math.floor(this.data[0])+'px';
else zxcOpacity(this.obj,this.data[0]);
}
}
function zxcOpacity(obj,opc){
if (opc<0||opc>100) return;
obj.style.filter='alpha(opacity='+opc+')';
obj.style.opacity=obj.style.MozOpacity=obj.style.KhtmlOpacity=opc/100-.001;
}
initialise by (just before the </BODY> tag) ie one the page has loaded
Code:
var M=new MenuPop({
MenuArray:menu,
EffectDuration:500
});
Bookmarks