Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have got a hover menu that is getting displayed on mouse over of every node of a treeview. This is working fine. What i want to do is to display sub menus on mouse over of the menu items.

Following is the code:

In HTML:

XML
<div id="hoverpopup" style="visibility:hidden; position:absolute; top:0; left:0;">
        <table bgcolor="#0000FF">
            <tr><td><font color="#FFFFFF">Option 1</font></td></tr>
            <tr><td bgcolor="#8888FF">Option 2</td></tr>
            <tr><td><font color="#FFFFFF"><a id="Option3" onmouseout="showhide('SubHover',false,'Option3');" onmouseover="showhide('SubHover',true,'Option3');">Option 3</a></font></td></tr>
            <tr><td bgcolor="#8888FF">Option 4</td></tr>
            <tr><td><font color="#FFFFFF">Option 5</font></td></tr>
            <tr><td bgcolor="#8888FF">Option 6</td></tr>
        </table>
    </div>
    <div id="SubHover" style="visibility:hidden; position:absolute; top:0; left:0;">
        <table>
            <tr><td bgcolor="gray">Option 3.1</td></tr>
            <tr><td bgcolor="#ffffff">Option 3.2</td></tr>
            <tr><td bgcolor="gray">Option 3.3</td></tr>
            <tr><td bgcolor="#ffffff">Option 3.4</td></tr>
        </table>
    </div>



In Javascript:

C#
//#############New Code###############
        var menuArray = new Array();
        menuArray[0] = 'hoverpopup';
        //menuArray[1] = 'submenu2';
        var globalObject = '';
        var isActive = false;
        var ourTimer;

        function showhide(obj,onlink,arg)
        {
            targetObject = document.getElementById(obj).style;

            globalObject = targetObject;
            if(onlink)
            {
                clearTimeout(ourTimer);

                for (i=0; i < menuArray.length; i++)
                {
                    var tempObject = document.getElementById(menuArray[i]).style;
                    tempObject.visibility = "hidden";
                }

                targetObject.visibility = 'visible';
                targetObject.position = "absolute";
                targetObject.top = getPosition(event).y;
                targetObject.left = getPosition(event).x;
                isActive = true;
            }
            else
            {
                isActive = false;
                layerTimer();
            }
        }

        function layerTimer()
        {
            ourTimer = setTimeout("hideMenu()",0750);
        }

        function hideMenu()
        {
            if( !isActive )
            {
                globalObject.visibility = 'hidden';
            }
        }

        function layerCheck(flag)
        {
            if(flag)
            {
                isActive = true;
                clearTimeout(ourTimer);
            }
            else
            {
                isActive = false;
                layerTimer();
            }
        }
        window.onload = function()
        {
            for(var i=0;i<menuArray.length;i++)
            {
                var id = menuArray[i];
                var e = document.getElementById(id);
                e.onmouseover = function(e)
                {
                    layerCheck(true);
                }
                e.onmouseout = function(e)
                {
                    layerCheck(false);
                }
            }
        }
        //############################


The problem here is, as soon as i mouse over on option 3, the sub menus appear, but the main menu disappears, because of the Mouseout event probably.

Can somebody tell me, how do i maintain the main menu, while displaying the sub menu on mouseover???

Best Regards,
Snigdharani Behera
Posted

1 solution

I have some ideas enjoy them.

1)
use setTimeout('onmouseout0', 1000); and have a public variable to manage your menus if the sub menu appears true the variable
then on onmouseout0 check the variable if the sub menu doesn't apper so call the main function of onmouseout.

2) use parent div container instead of use mouseout for each menu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900