【问题标题】:Open navigation drawer on swipe (Material Design Lite)滑动时打开导航抽屉(Material Design Lite)
【发布时间】:2023-11-08 18:01:01
【问题描述】:

我正在使用 Material Design Lite 在 Web 视图中为应用程序创建 UI,但是我遇到了一个问题,即我无法在滑动时部署导航抽屉。

我正在使用这个 jquery 代码来识别滑动事件

  $(function() {      
      $("#test").swipe( {
        //Generic swipe handler for all directions
        swipeRight:function(event, direction, distance, duration, fingerCount) {
          $(this).text("Event Triggered" );  
        },
      });
    });

从这里我不知道如何打开导航抽屉。我希望整个屏幕“可滑动”,尤其是左边缘。触发此滑动处理程序时如何打开导航栏?

【问题讨论】:

    标签: javascript jquery swipe-gesture material-design-lite


    【解决方案1】:

    我试图在演示材料设计精简版中添加此效果,http://www.getmdl.io/templates/dashboard/index.html。所以我找到的解决方案是通过material design lite生成的类“mdl-layout__drawer-button”来模拟汉堡按钮的点击事件。

    $(function() {      
        $("#test").swipe( {
            //Generic swipe handler for all directions
            swipeRight:function(event, direction, distance, duration, fingerCount) {
                $(".mdl-layout__drawer-button").click();                        
            },
        });
    });
    

    【讨论】:

    • 能否请您重写您的答案以适应开场白的需求,而不是仅仅处理您自己网站的一些代码。这将有助于开场白和其他读者,因为他们可以理解您的意思。
    • 这个解决方案很有效,我已经对其进行了编辑以适合我在原始帖子中使用的示例。谢谢
    • 您如何在 MDL 中使用滑动手势?好像它不支持开箱即用的手势。
    【解决方案2】:

    打开/关闭sidenav document.querySelector('.mdl-layout').MaterialLayout.toggleDrawer();

    【讨论】: