bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

scroll spy doesn't update active item in firefox

Open yeungda opened this issue 14 years ago • 19 comments

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

yeungda avatar Sep 06 '12 02:09 yeungda

This is working for me. Firefox 15 on Ubuntu Linux.

ramiro avatar Sep 06 '12 02:09 ramiro

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.

yeungda avatar Sep 06 '12 02:09 yeungda

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.

yeungda avatar Sep 06 '12 04:09 yeungda

Thanks, yeungda, for sharing this.

I've discovered this one as well - I appreciate your solution!

andyhausmann avatar Sep 26 '12 09:09 andyhausmann

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!

andrewdeandrade avatar Sep 26 '12 23:09 andrewdeandrade

Thanks for sharing @yeungda. Removing 100% from the body element fixed this for me as well.

BarisW avatar Nov 15 '12 07:11 BarisW

@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/

drainpip avatar Jan 07 '13 18:01 drainpip

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.

kirkegaard avatar Jan 09 '13 09:01 kirkegaard

Closing since it sounds like this was all resolved for you folks. Thanks!

mdo avatar Feb 06 '13 05:02 mdo

So, what's the fix, if you need 100% height on the body to get a sticky footer?

raphaotten avatar Feb 06 '13 14:02 raphaotten

https://github.com/twitter/bootstrap/issues/6484 has a hack you can try.

drainpip avatar Feb 06 '13 16:02 drainpip

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()

marcussjoholm avatar Mar 14 '13 10:03 marcussjoholm

@anderssonma , your solution is GREAT! You saved my day, thanks!

ivansammartino avatar Mar 21 '13 14:03 ivansammartino

Thanks :) glad to help. That hack should work as long as the document height is static - I think.

marcussjoholm avatar Mar 21 '13 15:03 marcussjoholm

Uhm... My document is static at the moment, maybe I can use a scrollspy refresh?

ivansammartino avatar Mar 21 '13 15:03 ivansammartino

Awesomeness!! Thanks anderssonma!

raphaotten avatar Mar 21 '13 16:03 raphaotten

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/

ivansammartino avatar May 07 '13 08:05 ivansammartino

Thaaanks!!!

dericklemos avatar May 13 '13 21:05 dericklemos

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.

SandyRig avatar Mar 05 '15 14:03 SandyRig