【问题标题】:prevent mmenu close on click on page防止在点击页面时关闭菜单
【发布时间】:2014-12-10 20:42:11
【问题描述】:

我有一个菜单实例。默认行为是当我在菜单外单击时它会关闭。我怎样才能防止这种行为?为了强制关闭菜单,我只想使用一个预先设置的按钮(已经工作)

------添加一些细节--------

我的菜单实例如下

<nav id="listPanel">
            <ul>
                <li id="closeButtonLi"><span id="panelButtonClose" class="glyphicon glyphicon-chevron-right"> Chiudi</span></li>
                <!--<li style="padding:10px"><input type="text" class="form-control" placeholder="Aggiungi atleta"></li>-->
                <li id="athSelectorLi" style="padding:10px">
                    <input id="athSelector" style="width:70%;"/>
                    <img id="plusButton" style="width:35px;height:auto;cursor:pointer;margin-left:12px;" src="../../../docsUI/images/common/add.png"/>
                    <img id="removeButton" style="width:35px;height:auto;cursor:pointer;margin-left:7px;" src="../../../docsUI/images/common/remove.png"/>
                </li>
                <li >
                    <table id="athTable" class="hover compact" width="95%" cellspacing="0">
                        <thead>
                            <tr>
                                <th>markerColor</th>
                                <th>bib</th>
                                <th>name</th>
                                <th>avgSpeed</th>
                                <th>locate</th>
                                <th>remove</th>
                            </tr>
                         </thead>
                         <tbody>
                        </tbody>
                    </table>
                </li>   
            </ul>
        </nav>  



     $(document).ready(function() {
        $("#listPanel").mmenu({
        "classes": "mm-light",
        "offCanvas": {
              "zposition": "front",
              "position": "right"
               }
        }
        });  

        $("#panelButton").click(function() {
             $("#listPanel").trigger("open.mm");
              });
        $("#panelButtonClose").click(function() {
             $("#listPanel").trigger("close.mm");
              });
        }); 

我需要的是仅使用关闭按钮关闭#listPanel 菜单

<li id="closeButtonLi"><span id="panelButtonClose" class="glyphicon glyphicon-chevron-right"> Chiudi</span></li>

在当前实现中,按钮按预期工作,但当我在页面其余部分的菜单外部单击时,菜单也会关闭。我想完全避免它(按http://mmenu.frebsite.nl/tutorial/open-and-close-the-menu.html 中所述的默认行为关闭菜单单击页面)

我在 Stack Overflow 当前答案和网站文档上都进行了搜索,但没有找到任何解决方案。唯一存在的 API 是 onClick,但它与我的需求无关。

【问题讨论】:

  • 这显然不是作为选项内置在 api 中的,这意味着您需要扩展插件。考虑到您没有表现出任何尝试,这超出了合理范围。

标签: mmenu


【解决方案1】:
$('#mm-blocker').unbind('mousedown')

【讨论】:

    【解决方案2】:

    这将删除 div,这将阻止关闭菜单

    $('#mm-blocker').remove();
    

    比解绑 mousedown 好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-28
      • 2021-12-26
      • 2014-12-25
      • 1970-01-01
      • 2018-02-16
      • 2021-07-06
      • 2011-10-13
      相关资源
      最近更新 更多