miromannino / Justified-Gallery

Javascript library to help creating high quality justified galleries of images. Used by thousands of websites as well as the photography community 500px.
http://miromannino.github.io/Justified-Gallery/
MIT License
1.68k stars 299 forks source link

Problem with scroll on mobile browser #300

Closed politvs closed 5 years ago

politvs commented 5 years ago

Hi, guys!

I've been testing Justified-Gallery and I find it really interesting. I put it to work in a desktop page, but I have found some problems getting it to work with a mobile browser (Android mobile Xiaomi Redmi 4X, Chrome browser). My scroll detection code is like this:

      $(window).on('scroll', addImagesOnScroll); 

      function addImagesOnScroll(){ 
        if($(window).scrollTop() + $(window).height() == $(document).height()) {
          blahblahblah();
        }
      }

For the mobile "edition" I tried with $(window).on('touchmove') with different conditions for detecting the end of page, without success.

Any clues? TIA

alanlanglois commented 5 years ago

@politvs try something like this, works for me:

document.addEventListener("touchmove", function(event){

   if($(window).scrollTop() + $(window).height() > $(document).height() ) {
        $('#gal').justifiedGallery('norewind');
    }
}, false);
politvs commented 5 years ago

@politvs try something like this, works for me:

document.addEventListener("touchmove", function(event){

   if($(window).scrollTop() + $(window).height() > $(document).height() ) {
        $('#gal').justifiedGallery('norewind');
    }
}, false);

Nope :( I have a bunch of different combinations, none of them are actually working on Chrome for mobile (on my Xiaomi at least). "touchmove" and "scroll" events fires, but they don't add any images. Works ok with my desktop browser and, funny thing, it also works with Xiaomi's own browser.

I don't know what else to do...

miromannino commented 5 years ago

I understand these problems, but this is beyond what JG should do. There are different ways to implement the infinite scroll and detect the user going at the bottom of the page. One way could be detecting the absolute coordinates (relative to the window) of an element that is at the bottom of the page.