简体   繁体   中英

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. 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:

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

You Don't need JavaScript to do This. Place a id="foo" to the panel title and go to it clickling a href="#foo" link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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