How to make an element active on hover, and remain active when im hovering over another specific div

BANGO

I have a menu bar with categories, when I hover a certain category a large drop down appear under it with subcategories.

I have already created it, you can see it here http://www.bootply.com/9Qz14HIz8R

Now when I hover the category its background change to gray, and when I move the cursor down to the subcategory drop down the grey background on the category is gone.

I want to find a way to make the category background gray when hovered, and then when I move the cursor to the subcategory drop down, i want the category to remain in gray background.

And when i move the cursor outside the subcategories drop down box then the category background will be gone.

I want to know what is the best way to achieve this.

I'm thinking that using js or jquery we can make the category active on hover and keep it active once cursor is on the subcategories drop down but make it inactive when the cursor moves out of the drop down box.

Any idea on how to solve this or if you suggest a different approach to achieve it.

Ghassan Elias

Add class name .active and on hover add style name to .services-shortcut

<style>
.services-shortcut {
    -webkit-transition: background-color 500ms linear 200ms;
    -o-transition: background-color 500ms linear 200ms;
    transition: background-color 500ms linear 200ms;

}
.services-shortcut:hover,
.services-shortcut.active {
    color: #555;
    background: none repeat scroll 0% 0% #ddd;
}
</style>

<script>
jQuery('div.dropdown').hover(function() {
    jQuery(this).find('.services-shortcut').addClass('active');
    jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
}, function() {
    jQuery(this).find('.services-shortcut').removeClass('active');
    jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
});
</script>

if you want to use .on() method do this:

jQuery('div.dropdown').on(
    'mouseenter', function () {
        jQuery(this).find('.services-shortcut').addClass('active');
        jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
    },
    'mouseleave', function () {
        jQuery(this).find('.services-shortcut').removeClass('active');
        jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
    }
);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

keep mouse over active if hovering over another overlapping element

How to scroll up a div when hovering over another element

Make an element appear and make adjustments when hovering over another element

How would I make the box-shadow of my div fade in on hover (and out when not hovering over it)?

How to change color of element when hovering over another element?

Make an element move by hovering over another element

Dropdown Hover State to stay active while hovering over child (text)

How to make parent div activate styling of child div for hover and active

How to display a div when hovering over another div

HTML/CSS How do I trigger another element when clicking :active or :hover?

How can I make a element show when hovering over another element, and hide it if not. And make it take up space the entire time

CSS Hover Opacity Transition flicker when hovering over element that is on top of another element

CSS how to select each li after the one im hovering, IF i hover over a specific child of that li

While hovering over one element, disable hover on another

jQuery hover - How to make div appear on hover, then remain visible

Expand/collapse div on hover - not collapsing when not active

Make a div appear on hover over another div

how to hide one div when another div is active in react js

Hide background layer on hover, reapers when hovering over <p> element

Show second div on hover and keep it visible with an active class on hover element

How make :focus, :active be the same as :hover

Change Styles Of Element When Another Element Is Active

How to activate a css function when you hover over another element

How can I change one svg path ID element when hovering over another element

Hover over one div make another disapear

WPF - hide element when hovering a mouse over another element

make div appear only on active state of another

How to make a DIV move when you hover over it

How to effectively make div scrollable on hover only, and have it stay in that position when not hovering?