我正在尝试使用MDCMenu 的文档menu.setAbsolutePosition(0, 100);
中找到的方法,将“mdc-menu”相对(波纹管)定位到我的顶栏上的溢出按钮,但它似乎没有做太多(实际上使元素卡在屏幕外),无论我设置什么值。
我创建了一个片段来说明这个问题:
<link rel="stylesheet" type="text/css" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<header class="mdc-top-app-bar">
<div class="mdc-top-app-bar__row">
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
<a href="#" class="material-icons mdc-top-app-bar__navigation-icon">menu</a>
<span class="mdc-top-app-bar__title">Title</span>
</section>
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
<div id="demo-menu" class="mdc-menu-surface--anchor">
<a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="More" alt="More">more_vert</a>
<div class="mdc-menu mdc-menu-surface">
<ul class="mdc-list" role="menu" aria-hidden="true" aria-orientation="vertical">
<li class="mdc-list-item" role="menuitem">
<span class="mdc-list-item__text">A Menu Item</span>
</li>
</ul>
</div>
</div>
</section>
</div>
</header>
<script>
var MDCMenu = mdc.menu.MDCMenu.attachTo(document.querySelector('.mdc-menu'));
MDCMenu.open = true;
// MDCMenu.hoistMenuToBody();
MDCMenu.setAbsolutePosition(0, 100);
</script>