An infinite scrolling plugin for jQuery.

Overview

jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging

Build Status npm version Bower version Join the chat at https://gitter.im/pklauzinski/jscroll

Official site at jscroll.com.

Requires jQuery v1.8.0+

Facebook Page

Follow us on Facebook for commit updates: https://www.facebook.com/jScroll.Infinite.Scrolling

Usage

The jscroll method is called on the selector for which you want your scrollable content contained within. For example:

$('.jscroll').jscroll();

The jscroll method takes an optional object literal as a parameter for overriding the default options. An example of how this can be done is shown below.

$('.jscroll').jscroll({
    loadingHtml: '<img src="loading.gif" alt="Loading" /> Loading...',
    padding: 20,
    nextSelector: 'a.jscroll-next:last',
    contentSelector: 'li'
});

Options

  • debug (false) - When set to true, outputs useful information to the console display if the console object exists.
  • autoTrigger (true) - When set to true, triggers the loading of the next set of content automatically when the user scrolls to the bottom of the containing element. When set to false, the required next link will trigger the loading of the next set of content when clicked.
  • autoTriggerUntil (false) - Set to an integer greater than 0 to turn off autoTrigger of paging after the specified number of pages. Requires autoTrigger to be true.
  • loadingHtml ('<small>Loading...</small>') - The HTML to show at the bottom of the content while loading the next set.
  • loadingFunction (false) - A JavaScript function to run after the loadingHtml has been drawn.
  • padding (0) - The distance from the bottom of the scrollable content at which to trigger the loading of the next set of content. This only applies when autoTrigger is set to true.
  • nextSelector ('a:last') - The selector to use for finding the link which contains the href pointing to the next set of content. If this selector is not found, or if it does not contain a href attribute, jScroll will self-destroy and unbind from the element upon which it was called.
  • contentSelector ('') - A convenience selector for loading only part of the content in the response for the next set of content. This selector will be ignored if left blank and will apply the entire response to the DOM.
  • pagingSelector ('') - Optionally define a selector for your paging controls so that they will be hidden, instead of just hiding the next page link.
  • callback (false) - Optionally define a callback function to be called after a set of content has been loaded.

For more information on the contentSelector option and how it loads a response fragment, see the jQuery documentation for the .load() method.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

LICENSES:

Comments
  • Doesn't stop loading

    Doesn't stop loading

    Hi there,

    I've tried to implement jScroll at http://dev.agderposten.no/cxense/va-lazy.php but the problem is it never stops loading. It's like I'm always at the bottom. I added autoTriggerUntil: 5 just to make it stop at some point.

    Any idea what could cause this? I've tried in Safari, Chrome and Firefox and I also tried removing the CSS but didn't help.

    bug 
    opened by espenlg 27
  • (about nextSelector) how to define it in pages where there's no 'Next' page, but only links to page 1,2,etc

    (about nextSelector) how to define it in pages where there's no 'Next' page, but only links to page 1,2,etc

    I've been trying to make this userscript in order to use jScroll it https://openuserjs.org/

    $('table')[0].jscroll({
      nextSelector: $('ul.pagination > li > a')[1],
      contentSelector: $('tbody:nth-of-type(1) > tr.tr-link').slice(0,24),
      callback: function () {
         $('ul.pagination')[1].remove();
      }
    });
    

    First of all, in that page, the "Scripts" table is the 1st (the other is the "Announcements" table), so I used $('table')[0].jscroll({. But, unfortunately I get $(...)[0].jscroll is not a function in FIrefox's Browser Console, therefore the script cannot be executed. Shouldn't this work, though?

    Also, the main problem is that, in that page, there's no 'Next' page, but only links to p.1,2,etc. So, I used nextSelector: $('ul.pagination > li > a')[1], as a reference, but, how could I select each nextSelector? (i.e. if I'm on page 1, the nextSelector will be the a to page 2. If then it paginates 2, it will be 3, etc)


    _The other selectors are: `contentSelector: $('tbody:nth-of-type(1) > tr.tr-link').slice(0,24),` i.e. the the 24 rows of the 1st table, and the `callback` function removes the 2nd "group" of links to next pages(i.e the one in the bottom), that is `$('ul.pagination')[1]`._ question 
    opened by darkred 12
  • Loads content early

    Loads content early

    This is the URL to reproduce:

    http://test.plumaz.com/library/

    I begin to scroll down and more content rows appear below before the getting to the scrolling point , ..

    What am I doing wrong ?

    opened by dmasson 12
  • jScroll always thinks user has scrolled beyond end of div - and immediately loads all pages.

    jScroll always thinks user has scrolled beyond end of div - and immediately loads all pages.

    Hi, I'm trying to use Jscroll to make a homepage of an image gallery script load the newest images as the user scrolls. A pretty standard usage of Jscroll I imagine. The problem I'm having is that Jscroll just loads every single page it can back to the beginning of time the moment it is triggered on the element, resulting it about 1GB of downloads and crashing the browser. To try to isolate the problem, I reduced the number of images per page down to one and extracted this example to its own page, but the problem persisted. `

    ` And the Javascript can be found in this paste http://pastebin.com/8Pphu1mq

    The final link in the html is recursive. I'm imagining that it should load the image again when I hit the bottom of the div of images, but what's happening is that the html just loads recursively, infinitely, until the browser crashes. Here's a sample from the browser console of debugging output that Jscroll makes when this happens. js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object js2.js:9432 jScroll: -8 from bottom. Loading next request... js2.js:9432 Object

    This is all it logs in the console no matter where I am scrolled in the div in question and no matter what browser I use. In MS Edge, it only actively loads pages while the user is actively scrolling, but in either direction. It might be worth noting that in my actual application, the console log's "-x from bottom", the x resembles the output of a random number generator set to generate numbers between 500 and 1000.

    question 
    opened by johncave 9
  • jScroll doesn't seem to work ok with a page displaying results in a table

    jScroll doesn't seem to work ok with a page displaying results in a table

    I've been trying to make this userscript in order to use jScroll it in thepiratebay (in the tables for Browse and Search results)

    $('#searchResult').jscroll({    
        nextSelector: $('a').has('img[src="https://piratebay.org/img/next.gif"]'),
        contentSelector: 'tr',
        callback: function() {$('tr.header').remove();}
    });
    

    Test link: https://thepiratebay.gd/browse/401 Note:the nextSelector is the link that appears with the ">" arrow icon.
    Unfortunately I got these problems:

    1. jScroll only appends (the cells of) page 2 and not the others too. Below is the HTML of the a tag of the "Next" link (FWIW, the href value is a relative link)

      <a href="/browse/401/1/3">
        <img src="https://piratebay.org/img/next.gif" alt="Next" border="0"></img>
      </a>
      

      And, as you can see, the "Next" <a> anchor tag has no id or class so I had to use a jQuery selector in nextSelector in order to select it.

    2. The rows from page 2 aren't properly aligned to the table from page 1. (screenshot) Isn't the contentSelector right?

    enhancement 
    opened by darkred 9
  • (in a userscript for reddit.com) It only appends page 2 when having login

    (in a userscript for reddit.com) It only appends page 2 when having login

    I've made this userscript in order to use jScroll it in reddit.com and any subreddit

    // ==UserScript==
    // @name        Reddit jScroll
    // @namespace   
    // @include     http://www.reddit.com/*
    // @version     1
    // @grant       none
    // @require     https://raw.githubusercontent.com/pklauzinski/jscroll/master/jquery.jscroll.min.js
    // ==/UserScript==
    
    $('span.nextprev').jscroll({
      contentSelector: 'div.content'   
    });
    

    where span.nextprev is the selector for the Next button and div.content is the selector for the links content of every next page.

    If open eg. reddit.com without login, then it works ok (it appends every next page). The problem is when I try my userscript having login: it only appends page 2, not the next pages (it just shows Loading... at the end of the appended page 2 ) for example in:

    1. http://www.reddit.com (I've only subscribed to 2 subreddits)
    2. eg. http://www.reddit.com/r/firefox/

    Is my userscript wrong or it'is jScroll?

    opened by darkred 9
  • Multiple jscroll in same page.

    Multiple jscroll in same page.

    How can I implement multiple jscroll in same page ?

    I tired to implement 2 jscroll, but only one works, If i comment one the other one works.How can i make both of them work ?

    regards, Prasanth

    opened by prasanthbendra 9
  • not working with contentSelector

    not working with contentSelector

    im using

        <script type="text/javascript">            
            $('.infinite-scroll').jscroll({
                debug: true,
                loadingHtml: '<img src="loading.gif" alt="Loading" /> Loading...',
                padding: 20,
                contentSelector: '.content',
                nextSelector: 'a.jscroll-next:last'                
            });                        
        </script>
    

    but in the log says:

    nextHref "page2.html .content .content" instead of "page2.html .content"

    if I remove the contentSelector will work ok but with the unwanted html

    opened by chulian1819 8
  • No next href present but it hit load function

    No next href present but it hit load function

    When I don't have any content to load still it hit load. In my page there is no next link. So I change some _setBindings() and added bellow two lines

    if (!$next.length)//if there is no next selector then don't need to bind scroll
       return false;
    
    _setBindings = function() {
                var $next = $e.find(_options.nextSelector).first();
                if (!$next.length)
                    return false;
                if (_options.autoTrigger && (_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0)) {
                    _nextWrap($next);
                    if (_$body.height() <= _$window.height()) {
                        _observe();
                    }
                    _$scroll.unbind('.jscroll').bind('scroll.jscroll', function() {
                        return _observe();
                    });
                    if (_options.autoTriggerUntil > 0) {
                        _options.autoTriggerUntil--;
                    }
                } else {
                    _$scroll.unbind('.jscroll');
                    $next.bind('click.jscroll', function() {
                        _nextWrap($next);
                        _load();
                        return false;
                    });
                }
            },
    

    I want to know is't correct or there is another way to do that or it has that type of functionality I implement it incorrectly that's why it hit load function thought there is no next page

    bug 
    opened by sumanta-ghosh 6
  • Can't get it to work

    Can't get it to work

    Am I the only one that can't get it to work?

    <html>
    <head>
        <style>
        </style>
        <script type="text/javascript" src="jscroll.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
        $(window).load(function(){
            $('.scroll').jscroll();
        });
        </script>
    </head>
    <body>
        <div class="scroll">
            <h3>Page 1</h3>
            <p>Content here...</p>
            <a href="example-page2.html">next page</a>
        </div>
    </body>
    </html>
    

    Nothing really happens.

    http://jsfiddle.net/d2Lrm2a5/

    opened by coldpumpkin 5
  • Added refresh option to reinitialize the plugin on each update when used to paginate search results dynamically updated with AJAX.

    Added refresh option to reinitialize the plugin on each update when used to paginate search results dynamically updated with AJAX.

    When paginating search results returned from an AJAX call...

    $('#search').keyup(function() {
        var search = $(this).val();
        $.get('/search', {search : search}, function(results) {
            $('.scroll-table').html(results);
            $('.scroll-table').jscroll();
        });
    });
    

    After getting the new set of search results, when we scroll to the bottom, jScroll appends content of the next page of the previous (old) query.

    So if my last _nextHref was "/search?query=A&page=3" and I enter B in the search field, instead of loading "/search?query=B&page=2" from the new href, it would load "/search?query=A&page=3" from the old href.

    Refresh option added to reinitialize the plugin on each load, to prevent it from loading the old href.

    Usage:

    $('.scroll').jscroll({
        refresh: true
    });
    
    enhancement 
    opened by orszaczky 5
  • loadingHtml not workig correctly with pjax

    loadingHtml not workig correctly with pjax

    Hi . i am using jscroll in pjax project and for loadingHtml i use below code loadingHtml: '<div class="text-center"><i class="fa fa-spinner fa-spin fa-fw"></i></div> Loading...',

    but i get Uncaught SyntaxError: Invalid or unexpected token error . but when i reload page everything is ok.

    opened by arbabi2010 0
  • Added autoTriggerRateLimit, autoTriggerPauseUntilLoaded functionality…

    Added autoTriggerRateLimit, autoTriggerPauseUntilLoaded functionality…

    … and autoTriggerLastFiredAt property to jScroll along with sensible defaults.

    I ran across the jScroll library in the wild... I noticed that particular implementation was a bit broken, from a low bandwidth users perspective, as the page kept auto triggering before any of the images even loaded... I'm sure this is the fault of the site developers, for not styling their HTML so their images had sensible pre-defined dimensions... but I thought I would contribute a simple patch to account for that.

    opened by rexfordkelly 0
  • jscroll is not a function

    jscroll is not a function

    I am including jscroll as follows:

    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/[email protected]/dist/jquery.jscroll.min.js"></script>
    <script>
    $(document).ready(function(){
        $('.scroll').jscroll({
                    autoTrigger: true,
                    loadingHtml: '<img class="center-block" src="/images/loading.gif" alt="Loading..." />',
                    padding: 0,
                    nextSelector: '.pagination li.active + li a',
                    contentSelector: 'div.infinite-scroll',
                    callback: function() {
                        $('ul.pagination').remove();
                    }
                });
        });
    </script>
    

    yet I am getting the error:

    jQuery.Deferred exception: $(...).jscroll is not a function TypeError: $(...).jscroll is not a function

    it's driving me crazy! any idea what's going on here? I am using it inside a Laravel blade.

    help wanted 
    opened by ilmam 1
  • documentation - detecting and destroying jscroll

    documentation - detecting and destroying jscroll

    I think it would be worth adding to the documentation, both in the README and on the jscroll.com website, how you can detect if jscroll is being applied and how to destroy it. This was important for me to know when to destroy the jscroll when switching from a scrolling tiles view to a list view. Something like this:

    if ($('#content-container').data('jscroll') && view != 'tiles') {
      $('#content-container').jscroll.destroy();
    }
    
    opened by opensourceame 0
  • jscroll does not load the new content all the time

    jscroll does not load the new content all the time

    Hello,

    I am using jscroll on a search page in a laravel app and it doesn't work all the time. Sometimes jscroll doesn't load the second page, I can see from the telescope that the jscroll has requested for the second page and that the app has returned a valid response. However, jscroll doesn't add the new content in the view and keeps on showing the loading html. I have attached an image of the developer tool's console log when the result does not load in the view.

    jscroll

    My jscroll js implementation looks like this.

    window.addEventListener('load', initSearch);
    
    function initSearch() {
        searchJScroll();
    }
    
    function searchJScroll() {
        const html = '<div class="text-muted align-items-center text-center"><i class="fas fa-2x fa-spinner fa-spin"></i> Loading...</div>';
        const options = {
            debug: true,
            autoTrigger: true,
            loadingHtml: html,
            padding: 0,
            nextSelector: '.pagination li.active + li a',
            contentSelector: '.jScroll',
            pagingSelector: '.pagination',
            callback: function () {
                $('ul.pagination').remove();
            }
        };
    
        $('.jScroll').jscroll(options);
    }
    

    Any insight would be greatly appreciated. Thanks.

    question 
    opened by munagurung 4
Releases(v2.4.1)
  • v2.4.1(Apr 11, 2018)

    • Corrected docs link to CDNJS minified version URL
    • Added query params to docs assets for cache-busting
    • Updated package-lock.json to propagate devDependencies correctly
    • Updated version to 2.4.1
    Source code(tar.gz)
    Source code(zip)
  • v2.4.0(Apr 10, 2018)

    • Added documentation site via docsify under /docs to allow the documentation to be versioned, hosted on GitHub, and easy to contribute to - jscroll.com will now be routed to this site
    • Updated grunt dependency to v1.0.2
    • Updated gruntify-eslint dependency to v4.0.0
    • Added package-lock.json
    • Updated minimum jQuery version to 1.8.0 to prevent vulnerability warnings
    • Changed jQuery from being included in dependencies to peerDependencies
    • Added grunt-contrib-uglify to dependencies
    • Added grunt uglify task and added it to the default task
    • Added npm run build script to run grunt default task
    • Added dist/jquery.jscroll.min.js from uglify task - fixes #133
    • Added eslint rule eol-last and set to never
    Source code(tar.gz)
    Source code(zip)
  • v2.3.9(May 31, 2017)

    • Added .editorconfig
    • Removed jshint and replaced with eslint
    • Added .eslintrc
    • Removed uglify and task to create minified version of jScroll source since this can be done on the user end, and it will also prevent conflicts in PRs
    • Removed jquery.jscroll.min.js
    Source code(tar.gz)
    Source code(zip)
  • v2.3.7(May 19, 2017)

Owner
Philip Klauzinski
Principal Software Architect
Philip Klauzinski
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
infiniteScrollWithTemplate - JQuery plugin for ajax-enabled infinite page scroll / auto paging with template

jQuery Infinite With Template Plugin JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little libr

이삼구 2 Mar 19, 2021
jQuery plugin for horizontally scrolling galleries

jQuery Horiztonal Scroll Gallery This jQuery plugin slides through a horiztonal gallery of items as you scroll down. It makes use of position:sticky s

Jeremy Rue 3 Feb 23, 2022
Parallax scrolling jQuery plugin

paroller.js A lightweight jQuery plugin that enables parallax scrolling effect You can use it on elements with background property or on any other ele

null 579 Dec 26, 2022
Javascript Library to create scrollable table with infinite rows and columns.

Fattable Demo Checkout the demo here. What is it? Fattable is a javascript Library to create table with infinite scroll, with infinite number of rows

Paul Masurel 477 Sep 19, 2022
Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks all textbooks 🔐 ∞

Brainly-LockPick ?? Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks textbooks ?? ∞ Note: refr

null 7 Dec 9, 2022
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed.

scrooth Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed. Why? I needed that, and I was unable to find p

Rafał Spiżewski 20 Aug 29, 2022
pagePiling plugin by Alvaro Trigo. Create a scrolling pile of sections. http://alvarotrigo.com/pagePiling/

pagePiling.js Pile your sections one over another and access them scrolling or by URL! Live demo Creating hugeinc.com website with pagePiling.js Who i

Álvaro 4.1k Dec 29, 2022
Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Paul B. Joiner 0 Dec 30, 2021
Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Erik Engervall 91 Dec 16, 2022
Dynamic web app 'presentations', driven by user scrolling, inspired by the NYT

Museé A small Typescript-based web app, inspired by the NYT Close Reading of Auden's Museé des Beaux Arts. Introduction I loved the NYT Close Reading

Timothy Danford 3 Mar 13, 2022
Given a list of items, only render what's visible on the screen while allowing scrolling the whole list.

Solid Windowed Given a list of items, only render what's visible on the screen while allowing scrolling the whole list. A Solid component. See https:/

Tito 40 Dec 21, 2022
A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

Mayank 7 Jun 27, 2022
Scrolling navigation component for web apps

Slinky.js Create beautiful scrolling driven navigation lists with stacking headers that remain visible at all times. Scroll around on the plugin homep

Sorin Iclanzan 201 Nov 16, 2022
A lightweight script to animate scrolling to anchor links.

DEPRECATION NOTICE: Smooth Scroll is, without a doubt, my most popular and widely used plugin. But in the time since I created it, a CSS-only method f

Chris Ferdinandi 5.4k Dec 26, 2022
A simple smooth scrolling using 100% vanilla JavaScript.

SmoothScroll.js A simple smooth scrolling using 100% vanilla JavaScript, and it's only 3kb! > Demo Usage // index.html <html> <head> <link rel="

Ray Chang 5 Aug 24, 2022