views:

26

answers:

1

I've got a DIV that shows on a hover event, and hides on a hover event on the #main div, but I can't help but feel like I've not done it correctly - more like a hacked together version ..

Can someone take a look and provide options for a more efficient way of doing it?

The jQuery

$(".sign_in").hover(function() {
      $("#sign_box").toggle();     
      return false;
  });
  $('#sign_box').hover(function() {
      $(this).show();
  });
  $("body #main").hover(function() {
      $("#sign_box").hide();
  });

The Markup

<div><a href="#" class="sign_in"><span>User Options</span></a></div>
    <div id="sign_box">
    <ul class="account-links">
        <li><%= Html.ActionLink<EventController>( x => x.List(), "All Events" )%></li>
        <li><%= Html.ActionLink<MyEventsController>( x => x.List(), "My Events" )%></li>
        <li><%= Html.ActionLink<AccountController>( x => x.Edit(), "My Profile" )%></li>
        <li><%= Html.ActionLink<ClubController>( x => x.List(), "All Clubs" )%></li>
        <li><%= Html.ActionLink<MyClubsController>( x => x.List(), "My Clubs" )%></li>
        <li><%= Html.ActionLink<AccountController>( x => x.ChangePassword(), "Change My Password" )%></li>
        <li><%= Html.ActionLink<DependantController>( x => x.List(), "My Dependants" ) %></li>
    </ul>
    </div>

The div sign_box is set to display:none ... let me know if you need to see the CSS as well..

A: 

Something like this perhaps...

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" ></script>
    <script>
    $(document).ready(function() {

        $(".sign_in, #sign_box").mouseover(function() {
            $("#sign_box").show();
            return false;
        });
        $('body').mouseover(function(){
            $("#sign_box").hide();
        });

    });
    </script>
    <style>
    body, html
    {
        height:100%;
        width:100%;
    }
    #sign_box
    {
        display:none;
        background-color:blue;
    }
    .sign_in{
        background-color:red;
    }
    ul, .sign_in, #sign_box
    {
        margin:0px;
        padding:0px;
        width:250px;
    }
    </style>
</head>
<body>
    <div class="sign_in">
        <a href="#" ><span>User Options</span></a>
    </div>
    <div id="sign_box">
        <ul class="account-links">
            <li>All Events</li>
            <li>My Events</li>
            <li>My Profile</li>
            <li>All Clubs</li>
            <li>My Clubs</li>
            <li>Change My Password</li>
            <li>My Dependants</li>
        </ul>
    </div>
</body>
</html>
Brandon Boone