简体   繁体   English

防止 <amp-sidebar> 从返回页面顶部

[英]Prevent <amp-sidebar> from going back to the top of the page

I'm trying to create a simple replacement for my previous hamburger menu, which had some navigation links that would simply scroll pageview to a specified section using href="#section" . 我正在尝试为我以前的汉堡菜单创建一个简单的替代品,它有一些导航链接,只需使用href="#section"将页面视图滚动到指定的部分。

Since I cannot use Checkbox trick anymore, I had to use <amp-sidebar> for it: 由于我不能再使用Checkbox技巧,我不得不使用<amp-sidebar>

<amp-sidebar id="sidebar" layout="nodisplay" side="right">
    <ul>
        <li>
            <a href="#secion1">Section 1</a>
        </li>
        <li>
            <a href="#secion2">Section 2</a>
        </li>
        <li>
            <a href="#secion3">Section 3</a>
        </li>
    </ul>
</amp-sidebar>

The problem is, that every time the sidebar is closed, the page gets scrolled back to it's top position (even the URL is reverted to the original state, so the #section is removed). 问题是,每次侧边栏关闭时,页面都会滚动回到它的顶部位置(即使URL恢复到原始状态,因此删除了#section )。

Is there any way to prevent this behavior? 有什么方法可以防止这种行为吗?

That behaviour seems like a bug. 这种行为似乎是个错误。 Please file an issue on the Github project: https://github.com/ampproject/amphtml/issues/new 请在Github项目上提出问题: https//github.com/ampproject/amphtml/issues/new

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM