1

When you are leaving the parent item of a submenu in jquery menu,there is a slight delay closing the submenu. any way to disable this and make it close instantly ?

*iknow its a EOL dead library but i'm asking just in case any of you guys remember something !

$(function() {
            $("#menu").menu();
});
#menu{
width:150px;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" crossorigin="anonymous" />

</head>
<body>
<ul id="menu">
                <li>
                    <div>W/O submenu</div>
                </li>

                 
                <li>
                <div>With submenu</div>
                <ul><li><div>Submenu</div></li></ul>
                    
                </li>

           </ul>
</body>
</html>

4
  • Works exactly the same way at their menu demo example, so probably not without digging into their code. Commented Apr 23, 2021 at 0:57
  • 1
    Some good news. The menu widget does have a 300 millisec delay. So, if you download the non-minified version of the js file (the second script line, remove the min. portion to save the file from the url) Then use that file locally. In the file, change the delay at line 4946 (in the menu widget, noted on line 4943) to a lower value, say 100, and then save, reload the page and check the behavior. Commented Apr 25, 2021 at 13:59
  • wow,thank you. i removed the delay parameter entirely,worked like a charm! you can post an answer if you 'd like some credit. Commented Apr 25, 2021 at 19:13
  • I don't know that I'd remove delay entirely, to avoid causing other possible trouble (as it's referenced in a few menu places), but set it to something very low, like 10 or 25 milliseconds to virtually be unnoticeable. I'll add an answer that is close to my comment. Commented Apr 25, 2021 at 20:28

2 Answers 2

2

The menu widget does have a 300 millisecond delay.

So, if you download the non-minified version of the js file, from here:

https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js (based on the OP's URL)

Then use that file locally. Then, in the file, change the delay at line 4946 (in the menu widget, noted on line 4943):

4943 var widgetsMenu = $.widget( "ui.menu", {
4944         version: "1.12.1",
4945         defaultElement: "<ul>",
4946         delay: 300,               // THIS delay
4947         options: {

...to a lower value, say 100 (or lower), and then save, reload the page, and check the behavior.

Note that I would not remove the delay entirely, as there are references to that attribute/property, but set it to a lower value as to be virtually unnoticeable.

Sign up to request clarification or add additional context in comments.

Comments

1

Searching through the jquery-ui source code here, I've found a way to do it without modifying jquery-ui. You can change the internal default like so:

$.ui.menu.prototype.delay = 0; // ms

Call this line before creating any menus. It looks like they needed this for unit tests or whatnot. Though, there are likely no guarantees this won't be broken by future releases (if any at this point in time).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.