简体   繁体   English

Bootstrap:anchar到面板标题

[英]Bootstrap: anchar to panel title

When I use an anchar link in my page, eg www.example.com/#about, my panel opens like it should. 当我在页面中使用anchar链接(例如www.example.com/#about)时,我的面板将按应有的方式打开。 However (on a page with scroll bars) when I click on a link, the page top is the body of the panel and not the title. 但是,当我单击链接时(在带有滚动条的页面上),页面顶部是面板的主体,而不是标题。 How can I make sure that I can always see the title? 如何确保我总是能看到标题?

<div id="accordion" role="tablist" aria-multiselectable="true">
    <div class="panel">
        <a role="button" data-toggle="collapse" data-parent="#accordion" href="#about" aria-expanded="false" aria-controls="about">Title</a>
        <div id="about" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo" style="height: auto;">
          <p>Body</p>
        </div>
    </div>
    /* other panels */
</div>

Javascript: Javascript:

location.hash && $(location.hash + '.collapse').collapse('show');

You Don't need JavaScript to do This. 您不需要JavaScript即可执行此操作。 Place a id="foo" to the panel title and go to it clickling a href="#foo" link 将id =“ foo”放置到面板标题中,然后单击href =“#foo”链接转到它

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

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