Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 831781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:15:40+00:00 2026-05-15T04:15:40+00:00

The site I’m working on has a collection of navigation elements across the top

  • 0

The site I’m working on has a collection of navigation elements across the top (“Products”, “Company”, etc.). When you mouse over the Products link, an overlay appears that shows a list of products with links to each. There’s a small link at the top of the container that, when clicked, closes the container. All of this works as advertised.

The client has asked that, once a user’s mouse pointer is a sufficient distance from the overlay element, the overlay element would close (without them having to click the ‘close’ link). This element appears on multiple pages that have disparate content, so I’m afraid it won’t be as simple as adding a mouseover listener to another single element within the page and have it work everywhere. My question, I suppose, is this: is there a relatively easy way to know when the mouse cursor is x pixels away from this container and trigger an event when this occurs?

My other thought is that I could just find several elements on the page that fit this criteria and add mouseover listeners to each, but I’m assuming there’s a more elegant way of handling this.

Thanks in advance – and please let me know if more detail is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:15:41+00:00Added an answer on May 15, 2026 at 4:15 am

    Here’s one example.

    http://jsfiddle.net/CsgFk/

    Calculate the bounds you want around the overlay, and set up a mousemove hanlder on the document, which tests to see if the mouse is outside the bounds.

    EDIT: It may be worthwhile to unbind the mousemove from the document when the overlay is hidden, and rebind it when revealed so that the mousemove isn’t constantly firing for no reason. Or at the very least, have the mousemove handler check to see if the overlay is already hidden before hiding it.

    HTML

    <div id='overlay'></div>​
    

    CSS

    #overlay {
        width: 200px;
        height: 200px;
        background: orange;
        position: relative;
        top: 123px;
        left:23px;
    }​
    

    jQuery

    var $ovl = $('#overlay');
    var offset = $ovl.offset();
    var height = $ovl.height();
    var width = $ovl.width();
    
    var bounds = {top: offset.top - 100,
                  bottom: offset.top + height + 100,
                  left: offset.left - 100,
                  right: offset.left + width + 100
                 }
    
    $ovl.mouseenter(function() {
        $ovl.stop().animate({opacity:1});
    });
    
        $(document).mousemove(function(e) {
        if(e.pageX < bounds.left ||
           e.pageX > bounds.right ||
           e.pageY < bounds.top ||
           e.pageY > bounds.bottom) {
               $ovl.stop().animate({opacity:.3});
        }
    });​
    

    EDIT:

    Here’s another idea (although it is heavily dependent on your layout). Place the overlay inside a container that has a large padding and remove the overlay when the pointer performs a mouseleave on the container. Again, this may not be feasible in your layout.


    EDIT:

    One other idea would be to set a delay on the code used to remove the overlay. Its not as precise, but may yield a sufficiently desirable effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The site I'm currently working on has a series of videos on a carousel
Site navigation html: <div class=main_nav> <div><a href=home/>Home</a></div> <div><a href=company/>Company</a></div> <div class=active><a href=franchise/>Franchise</a></div> </div> When
My site has quite a deep navigation structure and quite often it looks like
A site I'm working on has Flash headers (using swfobject to embed them). Now
site.com/link?p=2 give $_GET['p']==2 even though i've already made site.com/link rewrite to site.com/index.php?page=link So, i'm
My site, which is built on Python/Postgresql with django, has an area where you
Site structure: / /products /products/design /products/photo /about I want to see parent menu item
Site which I am developing has a menu with drop downs, which is always
Site 1 has dll's for x amount of object and data calls. Can Site
My site has a drop-down menu built in CSS and JavaScript that drops down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.