2

I have a navigation on my site where the last link opens a modal. Scrollspy is working fine but I don't want it to highlight the last element that opens the modal in any case.

Is there any way to do so?

    <nav>
        <ul class="nav">
            <li class="current">
                <a href="#home">Home</a>        
            </li>
            <li>
                <a href="#leistungen">Leistungen</a>        
            </li>
            <li>
                <a href="#">Preise</a>
            </li>
            <li>
                <a href="#">Referenzen</a>
            </li>
            <li>
                <a href="#contact" data-toggle="modal">Kontakt</a>      
            </li>
        </ul>
    </nav>

1 Answers1

0

I've found a solution without adding extra markup, but this is not so beautiful.

The scrollspy highlights the menu item only when the <a> contains the href attribute (at least, in Bootstrap 3.x). So if there's no href, the menu item will never be highlighted.

I've found an extension for the Bootstrap's scrollspy JS to exclude some items ID here, but this is for the 2.x version.

A solution for your problem may be :

<nav>
    <ul class="nav">
        <li class="current">
            <a href="#home">Home</a>        
        </li>
        <li>
            <a href="#leistungen">Leistungen</a>        
        </li>
        <li>
            <a href="#">Preise</a>
        </li>
        <li>
            <a href="#">Referenzen</a>
        </li>
        <li>
            <a data-toggle="modal" data-target="#contact">Kontakt</a> <!-- See http://getbootstrap.com/javascript/#modals-usage -->
        </li>
    </ul>
</nav>
Community
  • 1
  • 1
Epoc
  • 7,208
  • 8
  • 62
  • 66
  • Unfortunately it is not working for me. The active item is flickering on scrolling in my example. – Thomas Apr 18 '14 at 18:30