【问题标题】:Persistent drawers in Material ComponentsMaterial Components 中的持久抽屉
【发布时间】:2020-04-23 16:09:54
【问题描述】:

我正在尝试在 JavaScript 页面中使用抽屉,但从文档中我无法理解 HTML 组件如何与 Js 交互。

理想情况下,我希望通过仅包含 DOM 和 JS 而不使用任何外部 Web 框架来将模态抽屉添加到我的 HTML 页面。

我正在查看此文档: https://material.io/develop/web/components/drawers/

如果有人知道如何从按钮隐藏/显示。

谢谢

【问题讨论】:

标签: material-components-web


【解决方案1】:

MDC 中的所有组件都有几种不同的方式,您可以根据您使用的 JS 来初始化它们。因此,虽然我的示例使用了 javascript 的 CDN 版本,但您可以了解如何将我的示例转换为您使用的任何 JS 版本here

示例:https://codepen.io/MrSimmons/pen/LYperJx

基本上,您要做的是将绘图附加到绘图 html,然后单击按钮,触发绘图打开。

<aside class="mdc-drawer mdc-drawer--modal">
    ...
</aside>
// Create an instance of the draw
const drawer = mdc.drawer.MDCDrawer.attachTo(document.querySelector('.mdc-drawer'));

// On button click
document.querySelector('#open').addEventListener("click", ()=> {
    // Set the draw to whatever state it was not in last
    drawer.open = !drawer.open;
});

【讨论】:

    猜你喜欢
    • 2018-06-20
    • 2019-01-04
    • 2021-11-01
    • 2017-08-20
    • 2019-09-28
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2018-11-13
    相关资源
    最近更新 更多