Git Product home page Git Product logo

Comments (3)

jefflau avatar jefflau commented on June 15, 2024

I wrote some code to do this yesterday. It's not in the initial plugin. You'll need to delete the call to AjaxLoadMore.loadPosts() and then change the click/scroll functions to increment the pages after calling AjaxLoadMore.loadPosts().

In my version I've added an autoload/preload variable and made this optional

from ajax-load-more.

jefflau avatar jefflau commented on June 15, 2024

Add a new variable at the top:

var autoLoad = false;

add this before the the load more method AjaxLoadMore.loadPosts:

if (autoLoad === true) {
    $('#load-more').text("Loading...");
} else if (autoLoad === false) {
    $loading = false;
}

Then change your click and scroll handlers to this and add a conditional to increment the pages if you do decide to turn autoload on (can skip that if statement if you're never going to turn autoload on)

$button.click(function (e) {
    e.preventDefault();
    if (!$loading && !$finished && !$(this).hasClass('done')) {
        $loading = true;
        AjaxLoadMore.loadPosts();
        page++;
    }
});

if ($scroll) {
    $window.scroll(function () {
        var content_offset = $button.offset();
        if (!$loading && !$finished && $window.scrollTop() >= Math.round(content_offset.top - ($window.height() - 150)) && page < $max_pages) {
            $loading = true;
            AjaxLoadMore.loadPosts();
            page++;
        }
    });
}

if (autoLoad === true) {
    AjaxLoadMore.loadPosts();
    page++;
}

from ajax-load-more.

jefflau avatar jefflau commented on June 15, 2024

Yes, the JS file. I'm sorry I don't have time to make the changes for you, it took enough time to extract that from my own code.

Have a nice day.

from ajax-load-more.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.