I am looking for javascript and a basic tutorial on how to make mouse-over
drop-down menus--the type that when you "hover" over a subject links
relevant to that subject "emerge" which you can then "hover" over and click.
(see the links left on http://www.dpreview.com to see what I mean)
I have code from smartwebby.com (DHTML) but I'm not sure if it's the best,
and I'm not sure how to integrate any menus of my own into it. The code
follows:
******START OF CODE*********** *************** **
<script language = "Javascript ">
<!--
/**
* DHTML dropdown menu script. Courtesy of SmartWebby.com
(http://www.smartwebby.com/dhtml/)
*/
var bName = navigator.appNa me;
var bVer = parseInt(naviga tor.appVersion) ;
var NS6 = (bName == "Netscape" && bVer >= 5);
var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
window.onerror = null;
var menuActive = 0
var menuOn = 0
var onLayer
var timeOn = null // LAYER SWITCHING CODE
if (NS4 || IE4 || NS6) {
if (navigator.appN ame == "Netscape" && !document.getEl ementById){
layerStyleRef=" layer.";
layerRef="docum ent.layers";
styleSwitch="";
layerVis="show" ;
layerHid="hide" ;
}
else if (!document.all && document.getEle mentById) {
layerStyleRef=" layer.style.";
layerRef="docum ent.getElementB yId";
styleSwitch=".s tyle";
layerVis="visib le";
layerHid="hidde n";
}
else {
layerStyleRef=" layer.style.";
layerRef="docum ent.all";
styleSwitch=".s tyle";
layerVis="visib le";
layerHid="hidde n";
}
}
// SHOW MENU
function shLayer(layerNa me){
img = getImage("imgTa bs");
x = getImagePageLef t(img);
y = getImagePageTop (img);
menuTop = y + 20 ; // LAYER TOP POSITION
SerL = x + 55 ; // 'Ser' LAYER LEFT POSITION
ProL = x + 120 ; // 'Pro' LAYER LEFT POSITION
RatL = x + 260 ; // 'Rat' LAYER LEFT POSITION
if (NS4 || IE4 || NS6) {
if (timeOn != null) {
clearTimeout(ti meOn)
hideLayer(onLay er)
}
if (NS4 || IE4) {
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .visibility="'+ layerVis+'"');
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .top="'+menuTop +'"');
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .left="'+eval(l ayerName+'L')+
'"');
}
if (NS6) {
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.visibility=" '+layerVis+'"') ;
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.top="'+menuT op+'"');
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.left="'+eval (layerName+'L') +
'"');
}
onLayer = layerName
}
}// HIDE MENU
function hideLayer(layer Name){
if (menuActive == 0) {
if (NS4 || IE4) {
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .visibility="'+ layerHid+'"');
}
if (NS6) {
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.visibility=" '+layerHid+'"') ;
}
}
}// TIMER FOR BUTTON MOUSE OUT
function btnTimer() {
timeOn = setTimeout("btn Out()",1000)
}// BUTTON MOUSE OUT
function btnOut(layerNam e) {
if (menuActive == 0) {
hideLayer(onLay er)
}
}// MENU MOUSE OVER
function menuOver(itemNa me) {
clearTimeout(ti meOn)
menuActive = 1
}// MENU MOUSE OUT
function menuOut(itemNam e) {
menuActive = 0
timeOn = setTimeout("hid eLayer(onLayer) ", 400)
}// SET BACKGROUND COLOR
function setBgColor(laye r, color) {
if (NS6){
eval('document. getElementById( "'+layer+'").st yle.backgroundC olor="'+color+' "
');
}
else if (NS4){
eval('window.do cument.layers["'+layer+'"].document.bgCol or="'+color+'"' );
eval('window.do cument.layers["'+layer+'"].saveColor="'+c olor+'"');
}
else if (IE4){
eval('document. all.'+layer+'.s tyle.background Color="'+color+ '"');
}
}
function getImage(name) {
if (NS4 || NS6) {
return findImage(name, document);
}
if (IE4 || NS6)
return eval('document. all.' + name);
return null;
}
function findImage(name, doc) {
var i, img;
for (i = 0; i < doc.images.leng th; i++)
if (doc.images[i].name == name)
return doc.images[i];
for (i = 0; i < doc.layers.leng th; i++)
if ((img = findImage(name, doc.layers[i].document)) != null) {
img.container = doc.layers[i];
return img;
}
return null;
}
function getImagePageLef t(img) {
var x, obj;
if (NS4 || NS6) {
if (img.container != null)
return img.container.p ageX + img.x - 1;
else
return img.x - 1;
}
if (IE4) {
x = 0;
obj = img;
while (obj.offsetPare nt != null) {
x += obj.offsetLeft;
obj = obj.offsetParen t;
}
x += obj.offsetLeft;
return x;
}
return -1;
}
function getImagePageTop (img) {
var y, obj;
if (NS4 || NS6) {
if (img.container != null)
return img.container.p ageY + img.y;
else
return img.y;
}
if (IE4) {
y = 0;
obj = img;
while (obj.offsetPare nt != null) {
y += obj.offsetTop;
obj = obj.offsetParen t;
}
y += obj.offsetTop;
return y;
}
return -1;
}
// -->
</script>
******END OF CODE*********** *************** *****
Tips?
LRH
drop-down menus--the type that when you "hover" over a subject links
relevant to that subject "emerge" which you can then "hover" over and click.
(see the links left on http://www.dpreview.com to see what I mean)
I have code from smartwebby.com (DHTML) but I'm not sure if it's the best,
and I'm not sure how to integrate any menus of my own into it. The code
follows:
******START OF CODE*********** *************** **
<script language = "Javascript ">
<!--
/**
* DHTML dropdown menu script. Courtesy of SmartWebby.com
(http://www.smartwebby.com/dhtml/)
*/
var bName = navigator.appNa me;
var bVer = parseInt(naviga tor.appVersion) ;
var NS6 = (bName == "Netscape" && bVer >= 5);
var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
window.onerror = null;
var menuActive = 0
var menuOn = 0
var onLayer
var timeOn = null // LAYER SWITCHING CODE
if (NS4 || IE4 || NS6) {
if (navigator.appN ame == "Netscape" && !document.getEl ementById){
layerStyleRef=" layer.";
layerRef="docum ent.layers";
styleSwitch="";
layerVis="show" ;
layerHid="hide" ;
}
else if (!document.all && document.getEle mentById) {
layerStyleRef=" layer.style.";
layerRef="docum ent.getElementB yId";
styleSwitch=".s tyle";
layerVis="visib le";
layerHid="hidde n";
}
else {
layerStyleRef=" layer.style.";
layerRef="docum ent.all";
styleSwitch=".s tyle";
layerVis="visib le";
layerHid="hidde n";
}
}
// SHOW MENU
function shLayer(layerNa me){
img = getImage("imgTa bs");
x = getImagePageLef t(img);
y = getImagePageTop (img);
menuTop = y + 20 ; // LAYER TOP POSITION
SerL = x + 55 ; // 'Ser' LAYER LEFT POSITION
ProL = x + 120 ; // 'Pro' LAYER LEFT POSITION
RatL = x + 260 ; // 'Rat' LAYER LEFT POSITION
if (NS4 || IE4 || NS6) {
if (timeOn != null) {
clearTimeout(ti meOn)
hideLayer(onLay er)
}
if (NS4 || IE4) {
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .visibility="'+ layerVis+'"');
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .top="'+menuTop +'"');
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .left="'+eval(l ayerName+'L')+
'"');
}
if (NS6) {
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.visibility=" '+layerVis+'"') ;
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.top="'+menuT op+'"');
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.left="'+eval (layerName+'L') +
'"');
}
onLayer = layerName
}
}// HIDE MENU
function hideLayer(layer Name){
if (menuActive == 0) {
if (NS4 || IE4) {
eval(layerRef+'["'+layerNam e+'"]'+styleSwitch+' .visibility="'+ layerHid+'"');
}
if (NS6) {
eval(layerRef+' ("'+layerName+' ")'+styleSwitch +'.visibility=" '+layerHid+'"') ;
}
}
}// TIMER FOR BUTTON MOUSE OUT
function btnTimer() {
timeOn = setTimeout("btn Out()",1000)
}// BUTTON MOUSE OUT
function btnOut(layerNam e) {
if (menuActive == 0) {
hideLayer(onLay er)
}
}// MENU MOUSE OVER
function menuOver(itemNa me) {
clearTimeout(ti meOn)
menuActive = 1
}// MENU MOUSE OUT
function menuOut(itemNam e) {
menuActive = 0
timeOn = setTimeout("hid eLayer(onLayer) ", 400)
}// SET BACKGROUND COLOR
function setBgColor(laye r, color) {
if (NS6){
eval('document. getElementById( "'+layer+'").st yle.backgroundC olor="'+color+' "
');
}
else if (NS4){
eval('window.do cument.layers["'+layer+'"].document.bgCol or="'+color+'"' );
eval('window.do cument.layers["'+layer+'"].saveColor="'+c olor+'"');
}
else if (IE4){
eval('document. all.'+layer+'.s tyle.background Color="'+color+ '"');
}
}
function getImage(name) {
if (NS4 || NS6) {
return findImage(name, document);
}
if (IE4 || NS6)
return eval('document. all.' + name);
return null;
}
function findImage(name, doc) {
var i, img;
for (i = 0; i < doc.images.leng th; i++)
if (doc.images[i].name == name)
return doc.images[i];
for (i = 0; i < doc.layers.leng th; i++)
if ((img = findImage(name, doc.layers[i].document)) != null) {
img.container = doc.layers[i];
return img;
}
return null;
}
function getImagePageLef t(img) {
var x, obj;
if (NS4 || NS6) {
if (img.container != null)
return img.container.p ageX + img.x - 1;
else
return img.x - 1;
}
if (IE4) {
x = 0;
obj = img;
while (obj.offsetPare nt != null) {
x += obj.offsetLeft;
obj = obj.offsetParen t;
}
x += obj.offsetLeft;
return x;
}
return -1;
}
function getImagePageTop (img) {
var y, obj;
if (NS4 || NS6) {
if (img.container != null)
return img.container.p ageY + img.y;
else
return img.y;
}
if (IE4) {
y = 0;
obj = img;
while (obj.offsetPare nt != null) {
y += obj.offsetTop;
obj = obj.offsetParen t;
}
y += obj.offsetTop;
return y;
}
return -1;
}
// -->
</script>
******END OF CODE*********** *************** *****
Tips?
LRH
Comment