Twitter Bootstrap: Affix not triggering in single page application
Asked Answered
R

1

5

I am doing a Single Page Application and using Twitter Bootstrap. I am trying to use the Affix like so:

<div data-spy="affix" data-offset-top="100">

When I refresh the page, everything works fine, the bootstrap affix adds a class like so:

<div class="affix-top" data-spy="affix" data-offset-top="100">

and after I go past 100px, it changes it to class="affix". However, if I click off this page and come back, it no longer adds any classes to my div. In fact, it does not trigger the function in bootstrap at all to set the actions to check the position, etc.

Any insight would be great in how I can manually trigger it when I need to?

Rumor answered 24/6, 2013 at 18:58 Comment(0)
L
4

You might need to reinitialize the affix plugin with something like $('.affix-container').affix({offset: { top: 100 }}); when the page is redrawn.

Lezlie answered 24/6, 2013 at 19:3 Comment(4)
ouch, that's kind of what i'm trying to avoidRumor
the data attributes will only be trigger on page loadStratosphere
@MuhaiminAbdul: Do you have any reference on that?Lashawnda
Whoo! This worked for my use case. Ive spent all morning trying to figure this out.Deceased

© 2022 - 2024 — McMap. All rights reserved.