JSFiddle - React, Tailwind, and code Playground

HTML

<html>
<body style="min-height: 100%;">
    <p>Scroll will not be triggered, because the scroll height is smaller than the window height</p>
    <div class="container">Placeholder 1</div>
    <div class="container">Placeholder 2</div>
    <div class="container">Placeholder 3</div>
    <div class="container">Placeholder 4</div>
    <div class="container">Placeholder 5</div>
    <div class="container">Placeholder 6</div>
</body>
</html>

CSS

.container {
  height: auto;
}

.container:nth-child(even) {
  background-color: lightblue;
}

JavaScript

$(document).ready(function () {
    var flag = 0;

    function get_filter(class_name) {
        var filter = [];
        $('.' + class_name + ':checked').each(function () {
            filter.push($(this).val());
        });
        return filter;
    }

    function filter_data() {

        $.post( "fetch.php", {
            action  : 'fetch_data',
            cate    : get_filter('cate'),
            brand   : get_filter('brand'),
            model   : get_filter('model'),
            sort    : get_filter('sort'),
            date    : get_filter('date'),
            offset  : flag,
            limit   : 4
        } )
        .done( function (data) {

            console.log('data received');

            /**
             * TODO: do you want to override the existing data or append the new data?
             */
            //$('.filter_data').html(data); // override
            $('.filter_data').append(data); // append
        })
        .fail( function( error ) {

            console.log( 'An error occurred while fetching', error )
        });
    }


    $('.filter_all').click(function () {
        filter_data();
    });


    filter_data();


    var $window = $( window );
    var $document = $( document );

    $window.scroll(function () {

        // RUN when the page is almost at the bottom
        if ( $window.scrollTop() >= $document.height() - $window.height() - 300 ) {

            console.log('infinite scroll');
            alert('infinite scroll')

            flag += 4; // AUTO IN INCREMENT
            filter_data();
        }
    });
});