scroll spy doesn't update active item in firefox
We're using scroll spy in our application and have noticed a problem with firefox. Scroll spy is not updating the active list item in firefox when scrolling down the screen. This issue is evident on the scroll spy demo here:
http://twitter.github.com/bootstrap/javascript.html#scrollspy
I've been testing using mac os x 10.8.1 with firefox 15 and Aurora 17.0a2 (2012-09-02).
This is working for me. Firefox 15 on Ubuntu Linux.
Sorry about this, I think my report could have been clearer. Whilst in our application what I'm describing happens (I'm not sure why yet), I've noticed the situation is a bit different in the demo.
It also works for me when I first visit the page. If the scroll spy plugin loads when at at the bottom of the example page, it stays stuck to the bottom.
This could happen by loading the page normally and scrolling down before the plugin has finished loading. It could also happen if you scroll to the bottom and refresh.
We have tracked down the issue we were having with our site. It is completely different to the demo site issue unfortunately. It is also quite obscure.
When using height 100% for both html and body, scroll spy calculates the scrollHeight and maxScroll incorrectly in firefox. On our website, scrollHeight is usually something like 3753 and maxScroll is 3375. When html and body are height 100%, scrollHeight is 378 and maxScroll is 0.
We have fixed the issue by applying the height style to only html.
Thanks, yeungda, for sharing this.
I've discovered this one as well - I appreciate your solution!
Hey @yeungda,
Thanks for opening this issue! Unfortunately, it looks like it fails to pass the criteria neccessary for submitting to bootstrap. The following things are currently failing:
- should include a jsfiddle/jsbin illustrating the problem if tagged with js but not a feature
For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.
thanks!
Thanks for sharing @yeungda. Removing 100% from the body element fixed this for me as well.
@malandrew
I have included a jsfiddle with a basic example of the issue. When using 100% height on the body, Firefox breaks up using scrollspy. Unfortunately for me, my design requires a sticky footer.
- Works in Chrome / IE / Safari
- Broken in FF / Opera
- Removing 100% body height fixes issue
Here is the jsfiddle: http://jsfiddle.net/drainpip/mGWVy/
I have the same issue, but i dont have a height on the body and html element. It fails in my firefox and sets the the last item to active.
Here is the page http://herrbartels.dk/
EDIT: Turns out the problem was my content element. Had a position: absolute on it which makes it calculate the scrollheight wrong.
Closing since it sounds like this was all resolved for you folks. Thanks!
So, what's the fix, if you need 100% height on the body to get a sticky footer?
https://github.com/twitter/bootstrap/issues/6484 has a hack you can try.
If you "spy" on the body or the entire document this hack seems to work for me.
I replace this line scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
with just scrollHeight = $(document).height()
@anderssonma , your solution is GREAT! You saved my day, thanks!
Thanks :) glad to help. That hack should work as long as the document height is static - I think.
Uhm... My document is static at the moment, maybe I can use a scrollspy refresh?
Awesomeness!! Thanks anderssonma!
Here is a working example with multiple 100% divs (wrappers), based on great @anderssonma workaround: the trick with multiple divs is to wrap the scrollspy refresh in a window resize function... Sticky footer and scrollTo implementation included: http://www.iwstudio.it/scrollspy/
Thaaanks!!!
Thanks for sharing this @yeungda. I fixed it using body height 100% but it didnt work on Firefox. After wasting so much time found your answer. Applying height 100% to the HTML tag fixes the issue both for Chrome and Firefox.