Giter Site home page Giter Site logo

kamens / jquery-menu-aim Goto Github PK

View Code? Open in Web Editor NEW
7.7K 400.0 1.1K 2.59 MB

jQuery plugin to fire events when user's cursor aims at particular dropdown menu items. For making responsive mega dropdowns like Amazon's.

Home Page: http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown

JavaScript 100.00%

jquery-menu-aim's Introduction

jQuery-menu-aim

menu-aim is a jQuery plugin for dropdown menus that can differentiate between a user trying hover over a dropdown item vs trying to navigate into a submenu's contents.

Try a demo.

Amazon screenshot

This problem is normally solved using timeouts and delays. menu-aim tries to solve this by detecting the direction of the user's mouse movement. This can make for quicker transitions when navigating up and down the menu. The experience is hopefully similar to amazon.com/'s "Shop by Department" dropdown.

Use like so:

 $("#menu").menuAim({
     activate: $.noop,  // fired on row activation
     deactivate: $.noop  // fired on row deactivation
 });

...to receive events when a menu's row has been purposefully (de)activated.

The following options can be passed to menuAim. All functions execute with the relevant row's HTML element as the execution context ('this'):

 .menuAim({
     // Function to call when a row is purposefully activated. Use this
     // to show a submenu's content for the activated row.
     activate: function() {},

     // Function to call when a row is deactivated.
     deactivate: function() {},

     // Function to call when mouse enters a menu row. Entering a row
     // does not mean the row has been activated, as the user may be
     // mousing over to a submenu.
     enter: function() {},

     // Function to call when mouse exits a menu row.
     exit: function() {},

     // Function to call when mouse exits the entire menu. If this returns
     // true, the current row's deactivation event and callback function
     // will be fired. Otherwise, if this isn't supplied or it returns
     // false, the currently activated row will stay activated when the
     // mouse leaves the menu entirely.
     exitMenu: function() {},

     // Selector for identifying which elements in the menu are rows
     // that can trigger the above events. Defaults to "> li".
     rowSelector: "> li",

     // You may have some menu rows that aren't submenus and therefore
     // shouldn't ever need to "activate." If so, filter submenu rows w/
     // this selector. Defaults to "*" (all elements).
     submenuSelector: "*",

     // Direction the submenu opens relative to the main menu. This
     // controls which direction is "forgiving" as the user moves their
     // cursor from the main menu into the submenu. Can be one of "right",
     // "left", "above", or "below". Defaults to "right".
     submenuDirection: "right"
 });

menu-aim assumes that you are using a menu with submenus that expand to the menu's right. It will fire events when the user's mouse enters a new dropdown item and when that item is being intentionally hovered over.

Want an example to learn from?

Check out example/example.html -- it has a working dropdown for you to play with:

Example screenshot
Play with the above example full of fun monkey pictures by opening example/example.html after downloading the repo.

FAQ

  1. What's the license? MIT.
  2. Does it support horizontal menus or submenus that open to the left? Yup. Check out the submenuDirection option above.
  3. I work at a big company that requires a version number on this third party code before I can use it. Do you have a version number? Sure, current version: 1.1
  4. I'm not nearly bored enough. Got anything else? Read about this plugin's creation.

jquery-menu-aim's People

Contributors

kamens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-menu-aim's Issues

Destroy function?

I'm using the plugin on a responsive site, which uses a differently styled menu for the small screen view. I already have javascript in place to manage calling different functions depending on the viewport.

How can I turn off menu-aim so that I can manage the two different menus? The issue I have is when I render the page at a large viewport size and then resize to a small screen view - the menu-aim behaviors continue to occur, and I basically just want to turn them off.

enhancement if the submenu is not immediately adjacent to the menu (gap between both)

If the submenu is not immediately adjacent to the menu, there may be several prev locations outside of the menu, so that prevLoc bounds check will return false, and another submenu may be activated. TO avoid this, we return DELAY as soon as current loc is outside menu. This has to be inserted just before the prevLoc bounds check

            if (!prevLoc) {
                prevLoc = loc;
            }

           // start of new code to be inserted
            if (loc.x < offset.left || loc.x > lowerRight.x ||
                loc.y < offset.top || loc.y > lowerRight.y) {
                // If the mouse location is outside of the entire
                // menu bounds, don't change activation.
                return DELAY;
            }
           // end of inserted code 

            if (prevLoc.x < offset.left || prevLoc.x > lowerRight.x ||
                prevLoc.y < offset.top || prevLoc.y > lowerRight.y) {
                // If the previous mouse location was outside of the entire
                // menu's bounds, immediately activate.
                return 0;
            }

Does a non-jquery version exist?

Thank you for your work on making this pattern possible. I'm currently working on a project where we can't use jQuery. Do you know if anybody has turned this into a plain JS/DOM script yet?

Example without Bootstrap.css

Hi,
first of all: thank you very much. This is a very nice peace of code :)

I'd like to integrate this to my website, but it is allready a very big project. Integrating the whole bootstrap.css kills my site.
I tryed to build an example without the bootstrap.css, but it doesn't work. I allways forget some layers, some options or something - it allways kills the menue.

Is it possible for you to create an example with a simple css file - only options which are neccessary for the script? this might be a large help for me.

Thank you very much!
Stephan πŸ‘

Can get sub menu below to work....

Hi, I'm trying to get the drop down to work that appears below the main menu; however when I move the mouse from the main menu to the sub menu it disappears. I've put it on a test page here...

http://uk.monsoon.co.uk/view/content/ip-test

I've tried changing the top position and integrating some of the other pull requests on here but nothing has worked as if yet so any thoughts or suggestions would be appreciated! Code is below and can also be viewed on the source code of the page...Many thanks in advance

<script> var $menu = $(".dropdown-menu"); // jQuery-menu-aim: // Hook up events to be fired on menu row activation. $menu.menuAim({ activate: activateSubmenu, deactivate: deactivateSubmenu, submenuDirection: "below" }); // jQuery-menu-aim: // jQuery-menu-aim: the following JS is used to show and hide the submenu // contents. Again, this can be done in any number of ways. jQuery-menu-aim // doesn't care how you do this, it just fires the activate and deactivate // events at the right times so you know when to show and hide your submenus. function activateSubmenu(row) { var $row = $(row), submenuId = $row.data("submenuId"), $submenu = $("#" + submenuId), height = $menu.outerHeight(), width = $menu.outerWidth(); // Show the submenu $("div[rel='"+submenuId+"']").css('display','block'); $submenu.css({ display: "block", top: 25, left: 0, // main should overlay submenu height: height - 4 // padding for main dropdown's arrow }); // Keep the currently activated row's highlighted look $row.find("a").addClass("maintainHover"); } function deactivateSubmenu(row) { var $row = $(row), submenuId = $row.data("submenuId"), $submenu = $("#" + submenuId); // Hide the submenu and remove the row's highlighted look $("div[rel='"+submenuId+"']").css('display','none'); $submenu.css("display", "none"); $row.find("a").removeClass("maintainHover"); } // Bootstrap's dropdown menus immediately close on document click. // Don't let this event close the menu if a submenu is being clicked. // This event propagation control doesn't belong in the menu-aim plugin // itself because the plugin is agnostic to bootstrap. $(".dropdown-menu li").click(function(e) { e.stopPropagation(); }); $(document).click(function() { // Simply hide the submenu on any click. Again, this is just a hacked // together menu/submenu structure to show the use of jQuery-menu-aim. $(".mega-arrow").css("display", "none"); $(".popover").css("display", "none"); $("a.maintainHover").removeClass("maintainHover"); }); </script>

Publish to NPM?

I think it would be pretty useful to people if you were to publish to NPM to make it a little easier to pull into projects etc?

Iphone

Hi there,
the menu does not wrok when seen from an iPhone, is there a workaround?
thank you very much

Compatibility issue with displaing menu with jquery.stickyNavbar

First of all, thank you for this great plugin!
I'm having a problem using the megamenu with jquery.stickyNavbar
Reference:https://github.com/jbutko/stickyNavbar.js

Generally speaking when using a sticky nav, the nav file is called twice.
Once for for the standard view and, a second time for the sticky mode.

Being that the nav file is called twice, the first call cancels the second one.
In other words, the megamenu will only work in the standard view. When we slide down to sticky mode, then the submenu flyouts will not open.

Don't have a problem creating multiple megamenues on the same page since the fly outs all have 

unique id's. But in this case it creates a problem since standard & sticky mode menus are technically the same file.

    I was wondering if there was some solution where the same megamenu could be executed 

multiple times simultaneously on the same page. The only way I found to do this at this point is to duplicate the mega menu and alter the id's on the duplicate so they do not conflict with each other.

Hoping for a simpler solution since the megamenu is extensive and would like to avoid doing all the work twice.

Thanks for your help!!!!

Nested Menu with Menu-aim

I know there is a topic allready, but it is very old and no one replied.
Has anyone of you successfully implemented a multi level navigation with menu aim? The example has only one level, and I have at least there to deal with, its for category browsing with many child and grandchild categories.
But Nesting menuAim into itself does not seem to work out of the box.

Bug with the first row in a menu

There seems to be a bug where the first row won't be activated when opening a menu a second time if it was the row that was open before closing the menu.

I tested using the example in the repository and it also contains the bug, so I know it's not my own code causing it.

Steps to reproduce using the example.

  1. Click the menu and hover over the first item 'Patas'.
  2. Move off to the left and click to close the menu.
  3. Click the menu again and hover to the first item, it won't activate this time.

If you hover over any item other than the first one before closing the menu the bug doesn't occur.

Event is not attach in Sharepoint

Hi there,

I am not able to see Sub Menu item on Mouse Hover on Menu item after begging on Crome I founded control is not going to ActivateSubmenu function which I think is not attached.
When I am using this example with Sharepoint development.

While debugging I have got error while attaching events to be fired on menu row activation
Error is as follow:
"Uncaught Type Error: undefined is not a function"

$menu.menuAim({
activate: activateSubmenu,
deactivate: deactivateSubmenu
});

Looking forward for some solution

if Submenu is active

Hi, I love this project, but as I am very new to jquery, I cant make some specific action work.

I want to achieve double animation effect in menu. When I hover the mouse first time, I want the popover div to fade in, but if I hover mouse on another menu, I don't want fadein animation anymore.

Here is my code:

            function activateSubmenu(row) {
            var $row = $(row),
            submenuId = $row.data("submenuId"),
            $submenu = $("#" + submenuId),
            height = $menu.outerHeight(),
            width = $menu.outerWidth();

      if (// popover div is activated) 
          {
           $submenu.css({
    display: "block",
            top: -1,
            left: width - 0,  // main should overlay submenu
            height: height - 4, // padding for main dropdown's arrow
            }); } 

            else // if popover is not activated.
            {
    $submenu.css({
            top: -1,
            left: width - 0,  // main should overlay submenu
            height: height - 4, // padding for main dropdown's arrow
            })  .fadeIn(150);           
        }

            $row.find("a").addClass("maintainHover");
            }

Activating First Submenu

Would anyone know how to activate the first submenu from the initial list item?

For example using the current demo, when "Explore the Monkeys" is selected the "Patas" would open along with the submenu with the picture.

Thank you.

Bootstrap columns / rows

Is there a way to make columns and rows for the content that is shown after hover? That way it is possible to scale it to the right of the page, now it is a fixed width and when you reseize the browser at a certain point it overlaps and not all the content is shown. (hope I descripe this correctly)

"this" is NOT in fact the relevant row

readme.md states

All functions execute with the relevant row's HTML element as the execution context ('this'):

That seems to be incorrect, instead the relevant row is passed as the only parameter. Fixing this might be as simple as updating the readme?

First List Item Bug

The scenario is:
-> click "Explore the Monkeys" button
-> hover -only- over the first List item "Patas"
-> click anywhere on the page to close down the drop down menu
-> hover -again- over the first List item "Patas"
Bug: The first item doesn't show up again until hovering over other items first.

"Below" problems right to left

Great plugin.

I managed to almost everything work the ways that i intended.
The menu with " submenuDirection: 'below' " works fine if is left to right, but if is right to left simply it doesn't work.

Another minor thing is on " rowSelector: ".submenu-row-1" ".
for wordpress reasons i have

ccc = $(".submenu-holder-0");
    ccc.menuAim({
        rowSelector: ".submenu-title",
. . .
     <div class="submenu-holder-0">
           <div class="submenu-row-1" data-id="1547">
                  <div class="submenu-title">CAM</div>

And because the div is inside another, doesn't work as expected.

Menu on the right

Hi Developer,

I'm facing a problem with this jquery plugin. It is made for menus which are on the left, but my menu in black menu is on the right.
What things should I change to solve this problem?

Thanks in advance,

Carlos

Dymanic menu

Hi, congratulations ! The plugin is great !

I want to use it with a dynamic menu, but the plugin seems not firing the activate and deactivate function to show and hide the items. I think what is necessary is something like a LIVE method to do that. But as I am new to javascript and jquery, I need some help.

Thanks.

Having an issue with horizontal menus

Horizontal_Example

When going from Monitor to System Monitor (Hitting the black area), the exitMenu is triggered. I have configured the submenuDirection as "below". Is there anyway to prevent the exitMenu from being triggered?

The basic code layout is
< ul>
< li>
< a href ="#">System
< ul>
< li>Item1
< li>Item2
< /ul>
< /li>
< /ul>

Any suggestions?

Thanks

submenu cannot be triggered again after clicking close it in the example

If a menuitem is hovered, the submenu div will show up as expected, and clicking the area outside the menu, the submenu div will close, however when I hovered the same menuitem again, the submenu div didn't appear anymore unless I move to another menuitem and then move back.

    $(document).click(function() {
        // Simply hide the submenu on any click. Again, this is just a hacked
        // together menu/submenu structure to show the use of jQuery-menu-aim.
        $(".popover").css("display", "none");
    });

Maybe it has to do with the code above. I guess the code doesn't deactivate the menu properly.

menu-aim not working with SharePoint 2010 any idea

Hi there,

Great work, do you have any idea how we can use menu-aim with SharePoint 2010. I am facing problem:

I am not able to see Sub Menu item on Mouse Hover on Menu item after begging on Crome I founded control is not going to ActivateSubmenu function which I think is not attached.
When I am using this example with Sharepoint development.

While debugging I have got error while attaching events to be fired on menu row activation
Error is as follow:
"Uncaught Type Error: undefined is not a function"

$menu.menuAim({
activate: activateSubmenu,
deactivate: deactivateSubmenu
});

Looking forward for some solution

Delayed submenu on hover

Hi,

I used your tool for the navigation of my site. The navigation has 4 links, each with it's own submenu that appears on hover. The navigation is horizontal (unlike the monkey example, which is vertical) and I noticed that there is a lag when hovering from link1 to link2...as in, I hover over link1, link1's submenu appears, then I hover over link2 and it takes a second before link2's submenu appears. This is because the li's are floated, because when I got rid of this css and made the nav vertical there was no delay. Is there a way to get rid of this delay on a horizontal nav?

Thanks!

Re-entering a menu after exit

Firstly, thanks for the great work !

I'm currently having an issue; where once the 'exitMenu' option is called, the previous active item can no-longer be opened - until another row item is opened.

Is there a way to fix this ? Or am I using exitMenu incorrectly?

Thanks

Button Color

The color of the blue button in the menus seems off to me. The default color is very dull and so gives the appearance of being disabled. If the color was more saturated it would look better.

menu-aim inside menu-aim

How do you recommend me to put exactly a list menu like the one you have on the example, but this one inside the right panel that is shown actually when you hover an item so that this list also shows another side panel (a second one) when hovering?

Trailing comma

In the example and comments, the trailing comma on the last option will cause issues in IE:

deactivate: $.noop,

[enhancement] Add missing bower.json.

Hey, maintainer(s) of kamens/jQuery-menu-aim!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library kamens/jQuery-menu-aim is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "kamens/jQuery-menu-aim",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.