Dejan.S
Dejan.S

Reputation: 19158

How do i detect the next hover for mouse?

Hi Im building a menu and i need to detect the next move for the mouse. Currently im using event.relatedTarget and getting the event.relatedTarget.id of the next element. It worked until i had to make some modifications to my css in on my menu so i had to get rid of overflow: hidden; and use display: inline-block;. The thing that happens now is that the event.relatedTarget is an empty string except for when i pull the mouse fast down to my menu items. Ill post parts of the code and have the full thing on jsfiddle. any ideas guys?

link to the project

Navigation.top_links.on('mouseleave', function (event) {
                var sub_wrapper = $('.sub-wrapper'),
                        target_id = event.relatedTarget.id;

                console.log(event.relatedTarget.id);

                console.log(event.relatedTarget.id);
                if (target_id == 'got_me_sections' || target_id == 'got_me_products' || target_id == 'ind_sections' || target_id == 'ind_products') {                    
                    console.log('mouse down to items');
                    return false;
                }

                sub_wrapper.removeClass('sections').removeClass('products');
                sub_wrapper.hide();
            });

its much html so it gets kinda messy, sorry.

<ul id="top_nav">
                <li class="first"><a href="#" id="sections" class="nav-link">sections</a></li>
                <li><a href="#" id="products" class="nav-link">products</a></li>              
                <li>
                    <div id="nav_cart">
                        <div class="gfx-div-cart"></div>
                    </div>  
                </li>                
            </ul>         

        <div id="sub_nav">

            <div id="sub_sections" class="sub-wrapper">
                <div id="got_me_sections" class="top-space">
                    <div id="ind_sections" class="indicator"></div>
                </div>
                <div class="nav-items-wrapper">
                    <div class="nav-items-breadcrumb">
                        <ul class="breadcrumb">
                            <li class="bc first">sections</li>
                            <li class="bc last">&nbsp;</li>
                        </ul>
                    </div>
                    <div class="nav-items">
                        <ul class="nav-items-list">

                                   <li><a href="#" class="nav-item">item.Name</a></li>

                        </ul>
                    </div>
                </div>
            </div>
            </div>

Upvotes: 2

Views: 166

Answers (1)

Dejan.S
Dejan.S

Reputation: 19158

I solved this by adding css to the <div id="sub_nav">...</div>

i moved the container up a bit with negative margin-top: -4px;

Upvotes: 1

Related Questions