Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).scroll(function() not working on firefox?

Tags:

jquery

firefox

In order to load pages as facebook or twitter does at their sites, scrolling down, i have tried this with jquery:

$(window).scroll(function(){
    if  ($(window).scrollTop() == $(document).height() - $(window).height()){
        //do something
    }
}

And i am having troubles with Firefox. Not with Chrome and either with Safari (IE not tested yet).

If i use an "alert('xx')" inside the IF, Firefox crashes and i have to restart it.

I am using the Mac version of Firefox but i guess that's not an important fact.

Anyone have any idea about what's happening here? Thanks.

like image 818
Alvaro Avatar asked Feb 27 '12 19:02

Alvaro


2 Answers

I have the same problem: it works in chrome but not in firefox and IE. After debugging i found that there is a 1 px difference between $(document).height() - $(window).height() and $(window).scrollTop() in firefox but not in chrome. My working solution here:

    if  ($(window).scrollTop() + 1 >= $(document).height() - $(window).height()){

      //do something here

    }
like image 130
Devaroop Avatar answered Oct 16 '22 03:10

Devaroop


I know this is an really old article, but i was struggling with this today. I was trying to active an counter when it came into my viewport. It stopped working after i added some style to my style.css.

  html { 
    scroll-behaviour: smooth
  }

So, may this be in you favour, adding this will cause $(window).scroll function stop working on firefox and IE.

like image 4
jasper_prikr Avatar answered Oct 16 '22 04:10

jasper_prikr