[Javascript] Building menus

Dan Costea costea at ssi-schaefer-noell.com
Thu Feb 21 03:46:50 CST 2002


I write an example for you. It is working like this: on right click, the div
is dislpayed; on left click outside of the div, it is hidden. I made this
example working with IE 5.5 (I didn't test it with other browser).

<html>
<head>
<title> display:none test </title>

<script language="JavaScript">
<!--
function showMenu ()
{
 // if write click
 if (2 == event.button)
 {
  menu.style.top = event.y;
  menu.style.left = event.x;
  menu.style.display = "block";
 }
 else
 {
  menu.style.display = "none";
 }
}

function doSomething ()
{
 // your actions;

 // ...

 event.cancelBubble = true;
}
//-->
</script>

</head>

<body onMouseDown="showMenu ()" oncontextmenu="return false">

<div id="menu" style="position: absolute; display: none; width: 100; height:
200; border: #5267F8 2 groove;" onMouseDown="doSomething ()">
</div>

</body>
</html>







> Hi!
>
> I tried it but it doesn't work as I hope it would. If I click outside the
> menu it is still open.
>
>
> Bye,
>
> Iztok

> >
> > > Hi!
> > >
> > > I have a problem with a menu I'm building. I've built it with <div
> > > style="visibility: hidden/visible;"> and 'visibility' and 'hidden'
> > property
> > > is triggered by Javascript. But I want the menu to disappear if the
user
> > > clicks outside the menu. Anyone?
> > >
> > > Bye,
> > >
> > > Iztok
> >
> >
> > Use:  style="display: none/block".
> > (see:
> >
>
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref
> > erence/properties/display.asp)
> >
> >
> > Dan.
> >





More information about the Javascript mailing list