Understanding Scrollspy


Been spending the last hour trying to figure out how to get the scrollspy to work.

I’ve managed to get anchors themself to work just fine. What I’m trying to achieve here is exactly what is shown in the bootstrap example.

I’ve attached a picture where i have tried to explain as much as possible where’s what. That small container on the right side is initially empty, but information gets loaded to it on pageLoad with Ajax.

Image (self-hosted): https://i.axycloud.net/GPC_58MPsaC0spdj.png

Any pointers would be helpful.

I’m trying to get “Custom anchor” on the left side to highlight as im scrolling down the page.

Bootstrap docs says its supposed to get the “active” state. But it never gets it.

I just tested on a fresh project, and it works fine there. So i think the issue is that I load the anchors after the page has been loaded, so i will just stick with normal anchors.

Just wanted to mention it in case someone else stumbles across this thread.

1 Like

When adding or removing elements in the DOM, you’ll need to call the refresh method.
here is an example

You can read more about the methods here

Anybody having problems with scrollspy not working in firefox? Mines stopped working but was fine a couple of days ago :thinking:

Yes, it seems to be acting very erratically since the latest Firefox update. I don’t use Firefox often and I have updates set to manual. When I opened it before it asked me to update but I said no, and then I checked out a site I have using Scrollspy. It seemed to work fine. Then I applied the FF update (v 107), and now Scrollspy is working erratically on that same site.

Then I downgraded back to FF v106 and Scrollspy works correctly again. Not sure where we go from here?

@printninja It took a while to find out why it wasn’t working. It was down to all my sections anchors being in a main div and scrollspy being applied to the body. Removed scrollspy from the body and applied it to the main and it’s working now. :smiley:

I haven’t had time to investigate this more, but I will. I’ll post my findings (if any) here.