oclockvn
6/4/2018 - 2:08 PM

infinite-comic-loading.js

(function() {
    const images = [...document.querySelectorAll('#content img')];
    let i = 0;
    let len = images.length;

    //     window.onkeyup = function(e) {
    //         if (e.keyCode === 76 && i < len) { // l
    //             console.log('l is pressed. loading next...');

    //         }
    //     }

    document.body.innerHTML = '';
    document.head.innerHTML = '';

    function appendImage() {

        window.onscroll = function() {
            console.log('removed scroll');
        }
        
console.log('append image');
        var elem = document.documentElement;
        var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;

        if (elemScrolPosition === 0) {
            const img = "<p style='text-align: center'>" + images[i].outerHTML + "</p>";
            document.body.innerHTML += img;
            i++;
        }

        window.onscroll = function() {

            console.log('scroll again');

            appendImage();
        }
    }

    window.onscroll = function() {
        console.log('onscroll');
        appendImage();
    }
}
)();