metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

Load more with button, button not hidden #930

Closed thewebartisan7 closed 3 years ago

thewebartisan7 commented 3 years ago

I see an example that button for load more is hidden or disabled during request and then again visible on load. I see also source code of this. But when I try to use it, then it's always visible, and not disabled or hidden. I try with option loadOnScroll and scrollThreshold. Infinitescroll works fine, the problem is that I want to hide button view more during request.

Here is part of my code, please let me know what is wrong:

            const grid = document.querySelector('.grid')

            const viewMoreButton = document.querySelector('.view-more-button')
            viewMoreButton.style.display = 'block'

            const infScroll = new InfiniteScroll(grid, {
                path: 'a[rel="next"]',
                append: '.item',
                button: viewMoreButton.querySelector('.js-load-more'),
                status: '.page-load-status',
                //loadOnScroll: false, // Same not working also
                scrollThreshold: false, // Try also this but same
            })

            infScroll.on('load', function(response) {
                // I do something here with response...
            })
desandro commented 3 years ago

You can hide on [request](https://infinite-scroll.com/events.html#request), then show on load

infScroll.on( 'request', function( path ) {
  viewMoreButton.style.display = 'none';
});

infScroll.on( 'load', function( path ) {
  viewMoreButton.style.display = 'block';
});