-2

I am wondering if there's a tutorial to display a context-like menu when hovering a button, this is very similar to Google Plus onHover menu effect seen below:

enter image description here

Any tutorial on this is appreciated, thanks!

John Smith
  • 465
  • 4
  • 15
  • 38
  • I was thinking of a way to display it when hovering, like the usage of an "open" to "toggle" class, but not sure, any help or tutorial on this is appreciated, thanks a lot! – John Smith Oct 18 '13 at 12:39
  • 2
    [Type of Questions to Avoid](http://stackoverflow.com/help/dont-ask) – Alex W Oct 18 '13 at 12:39
  • @NathanLee do you know of any way to achieve this result? Thanks a lot in advance. – John Smith Oct 18 '13 at 12:41
  • Is your Google search broken? There are dozens of links you could follow instead of asking someone else to do the work for you, right? – David Navarre Oct 18 '13 at 12:42
  • 2
    I'm pretty sure you're trying to get us to do your work for you here...because you've obviously not even gone to google – pythonian29033 Oct 18 '13 at 12:42
  • 1
    LOL, I have Googled this for over a week now, and no result – John Smith Oct 18 '13 at 12:44
  • You are proably not using the right keywords. Regardless, this doesn't look diffcult to achieve and im sure there are thousands on ppl on SO who can answer this in 5 mins completely to the detail. But every1 would like to see you make an effort – MarsOne Oct 18 '13 at 12:47
  • You could take a look at how Bootstrap does it, http://getbootstrap.com/javascript/#dropdowns - Basically you'd have a `container element` with a `trigger` and a `menu` inside. When the trigger is clicked/hovered, the menu appears. – Matt W Oct 18 '13 at 13:11
  • 1
    @M_Willett thanks for you effort, but bootstrap is nothing I want to follow. If there's a better way to do this practically, I'd be happy to see the solutions or the tutorial on it, thanks a lot. – John Smith Oct 18 '13 at 13:13

6 Answers6

5

You might find the below link helpful:

http://medialize.github.io/jQuery-contextMenu/demo/trigger-hover-autohide.html

honor
  • 7,378
  • 10
  • 48
  • 76
  • 1
    This is very close to what I was looking for, is there a way to achieve this with pure CSS 2.0? – John Smith Oct 18 '13 at 12:47
  • You mean without any javascript or jquery? – honor Oct 18 '13 at 12:48
  • 1
    @sr. Yes if possible, not sure if G+ uses jQuery or if they achieved this with pure CSS. – John Smith Oct 18 '13 at 12:49
  • 2
    @JohnSmith, almost every website you see now uses jQuery. – MarsOne Oct 18 '13 at 12:51
  • The menu is drawn by the PHP when the page is generated, but it will remain hidden until Hover of course. – John Smith Oct 18 '13 at 12:51
  • @MarsOne sure, but what about backward-compatibility with older browsers? – John Smith Oct 18 '13 at 12:52
  • @john With CSS3 that could be done I think. With CSS2 I am not sure. – honor Oct 18 '13 at 12:52
  • Which older browsers are you talking about , IE6, IE7? jQuery 1.X is supported in ie6+, jquery 2.X is supported in ie9+. I think ie8 is almost dead now and dont even bother with 6 & 7 – MarsOne Oct 18 '13 at 12:53
  • 1
    @JohnSmith cleanest way will be to build and hide your HTML menu on your page, and show it using javascript on hover. That is all it takes. Easy :) What you want is a clean and nice looking menu like Google's. Showing and hiding is easy. But that sample I provided is also cool, and easy. You could still try that. – honor Oct 18 '13 at 13:02
  • Reagrding the code, the code is clean and minimal. Hardly 12 lines of it. – MarsOne Oct 18 '13 at 13:03
  • Check this http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered/184673#184673 for hilarious code – MarsOne Oct 18 '13 at 13:03
  • @MarsOne LOL! LOL! LOL! LOL! – John Smith Oct 18 '13 at 13:05
1

The best way in my opinion is using pure css

CSS:

.button {
    position: relative;
}

    .button .hovermenu {
        position: absolute;
        top: 25px;
        left: 0px;
        display: none;
    }

    .button:hover .hovermenu {
        display: block;
    }

HTML:

<ul>
    <li class="button">
        This has a hovermenu!
        <div class="hovermenu">
            <ul>
                <li>Submenu item</li>
            </ul>
        </div>
    </li>
</ul>
Tum
  • 6,937
  • 2
  • 25
  • 23
  • The advantage of this is that you can add as much buttons with a submenu as you like (`
  • `), and you only have to set the `top` and `left` right to position them all correctly relative to their parent menu item – Tum Oct 18 '13 at 12:52
  • provide a fiddle sample plz! Thanks a lot! – John Smith Oct 18 '13 at 12:58
  • @JohnSmith http://jsfiddle.net/Tumtum/gF7eh/ – Tum Oct 18 '13 at 16:15