Using free alignment
Free alignment is a very powerful feature, which allows you to build a navigation system to virtually any orientation you like. It also allows for multiple navbars to be created; you might, for example, want two horizontal navbars underneath each other, or a vertical and horizontal layout. This tutorial discusses a few of the possibilities, and suggests some ways of making complex layouts easier to maintain.
The first thing to do is switch on free alignment; by defining
menuALIGN as "free".
If you do this with an otherwise unedited script, the navbar will now look
like this.
As you'll see, the horizontal nav has gone. The individual link cells which were previously positioned relative to the horizontal container now take their positions from the x,y values defined in the addMainItem arrays, relative to absTOP and absLEFT:
addMainItem("index.html","Ultimate Dropdown Menu",192,"center","","",0,0,"u");
Two techniques
From this point on, there are two possible techniques for positioning the link cells:
Absolute positioning for cells in free alignment
Supposing then, that you want to build a vertical navbar. You could do something like this:
addMainItem("../index.shtml","Home",150,"center","","",20,20,"");
addMainItem("../music/index.shtml","Music",150,"center","","",50,20,"");
addMainItem("../scripts/index.shtml","Scripts",150,"center","","",80,20,"");
addMainItem("../games/index.shtml","Games",150,"center","","",110,20,"");
addMainItem("../mailme.shtml","Contact",150,"center","","",140,20,"");
Which looks like this.
Note that, contrary to convention, the first digit is the top (y) position and the second digit is the left (x) position. This is not intentional per se, it's simply too deeply embedded into the script's core architecture to change it now. Sorry if it's a bit disorientating at first ...
The top and left positions are defined assuming that
absTOP and
absLEFT are both 0.
However in practise
it's easier to define the position of the first link cell as
0,0 and use absTOP and
absLEFT to move it into place. This will allow
you to re-position the whole nav structure using those two global variables as a meaningful
anchor point:
var absLEFT = 20;
var absTOP = 20;
...
addMainItem("../index.shtml","Home",150,"center","","",0,0,"");
addMainItem("../music/index.shtml","Music",150,"center","","",30,0,"");
addMainItem("../scripts/index.shtml","Scripts",150,"center","","",60,0,"");
addMainItem("../games/index.shtml","Games",150,"center","","",90,0,"");
addMainItem("../mailme.shtml","Contact",150,"center","","",120,0,"");
This also assumes that all the link cells are the same height, but if any of your links contain line breaks then those cells will be taller, and so the next cell must be offset further. The scattered links demo is an example of this. Another thing you may find is that when you make global adjustments which affect the height of the cells, such as to vPADDING or fSIZE, all your y-position values need to be changed, because cells can overlap each other. This can rapidly become tedious if your site is at the design stage, so to make things easier in this situation, I recommend building an array of position values, and using it to define the main items:
var yPos = new Array(0,30,60,90,120);
addMainItem("../index.shtml","Home",150,"center","","",yPos[0],0,"");
addMainItem("../music/index.shtml","Music",150,"center","","",yPos[1],0,"");
addMainItem("../scripts/index.shtml","Scripts",150,"center","","",yPos[2],0,"");
addMainItem("../games/index.shtml","Games",150,"center","","",yPos[3],0,"");
addMainItem("../mailme.shtml","Contact",150,"center","","",yPos[4],0,"");
An array such as this is much easier to edit. You can also make it easier to re-arrange links and add others in between, by using this shorthand method for addressing the array:
var yPos = new Array(0,30,60,90,120);
i=0;
addMainItem("../index.shtml","Home",150,"center","","",yPos[i++],0,"");
addMainItem("../music/index.shtml","Music",150,"center","","",yPos[i++],0,"");
addMainItem("../scripts/index.shtml","Scripts",150,"center","","",yPos[i++],0,"");
addMainItem("../games/index.shtml","Games",150,"center","","",yPos[i++],0,"");
addMainItem("../mailme.shtml","Contact",150,"center","","",yPos[i++],0,"");
Actually in this case, every link cell is the same height, so we can make this even easier with only a single value to update:
var yPos = new Array;
var yp = 0;
for(i=0;i<5;i++){
yPos[i]=yp;
yp+=30;
}
i=0;
addMainItem("../index.shtml","Home",150,"center","","",yPos[i++],0,"");
addMainItem("../music/index.shtml","Music",150,"center","","",yPos[i++],0,"");
addMainItem("../scripts/index.shtml","Scripts",150,"center","","",yPos[i++],0,"");
addMainItem("../games/index.shtml","Games",150,"center","","",yPos[i++],0,"");
addMainItem("../mailme.shtml","Contact",150,"center","","",yPos[i++],0,"");
With a bit of practise, highly complex layouts are easy to build and maintain.
This example creates two navbars stretching out below
and to the right of the home cell:
var yPos = new Array;
var xPos = new Array;
var yp = 0;
var xp = 0;
for(i=0;i<6;i++){
yPos[i]=yp;
xPos[i]=xp;
yp+=30;
xp+=105;
}
addMainItem("../index.shtml","Home",100,"center","","",yPos[0],xPos[0],"");
addMainItem("../cooking/index.shtml","Cooking",100,"center","","",yPos[0],xPos[1],"");
addMainItem("../samples/index.shtml","Sample",100,"center","","",yPos[0],xPos[2],"");
addMainItem("../gear/index.shtml","Gear",100,"center","","",yPos[0],xPos[3],"");
addMainItem("../freeware/index.shtml","Freeware",100,"center","","",yPos[0],xPos[4],"");
addMainItem("../links/index.shtml","Links",100,"center","","",yPos[0],xPos[5],"");
addMainItem("../music/index.shtml","Music",100,"center","","",yPos[1],xPos[0],"");
addMainItem("../scripts/index.shtml","Scripts",100,"center","","",yPos[2],xPos[0],"");
addMainItem("../games/index.shtml","Games",100,"center","","",yPos[3],xPos[0],"");
addMainItem("../mailme.shtml","Contact",100,"center","","",yPos[4],xPos[0],"");
Which looks like this.
Don't worry if this seems confusing; you can define each position simply with numbers, and for your end user the result is the same. So the example above could also be created like this:
addMainItem("../index.shtml","Home",100,"center","","",0,0,"");
addMainItem("../cooking/index.shtml","Cooking",100,"center","","",0,105,"");
addMainItem("../samples/index.shtml","Sample",100,"center","","",0,210,"");
addMainItem("../gear/index.shtml","Gear",100,"center","","",0,315,"");
addMainItem("../freeware/index.shtml","Freeware",100,"center","","",0,420,"");
addMainItem("../links/index.shtml","Links",100,"center","","",0,525,"");
addMainItem("../music/index.shtml","Music",100,"center","","",30,0,"");
addMainItem("../scripts/index.shtml","Scripts",100,"center","","",60,0,"");
addMainItem("../games/index.shtml","Games",100,"center","","",90,0,"");
addMainItem("../mailme.shtml","Contact",100,"center","","",120,0,"");
Once your navbar looks okay, the next thing to do is add some menus.
The default positioning of a submenu is to be aligned against the bottom edge of its parent cell, so some, or most likely all of the submenus will need to be offset. The best approach to take depends on what you're building.
var vOFFSET = -27;
var hOFFSET = 155;
Applied to the vertical nav example earlier, this creates a large enough offset that the menus are aligned with the top-right of each link cell, like this.
0 and position each submenu
individually, eg:
defineSubmenuProperties(150,"left","left",-27,155,"");
Remember that menus which are aligned against their right edge take an inverse value for their x-offset.
Child menus do not need to be treated any differently, since their position is relative to their parent submenu's.