您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
jQuery Plugin for Infinite Scrolling / Auto-Paging
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/19670/125710/jScroll.js
jScroll is a jQuery plugin for infinite scrolling, written by Philip Klauzinski. Infinite scrolling; also known as lazy loading, endless scrolling, autopager, endless pages, etc.; is the ability to load content via AJAX within the current page or content area as you scroll down. The new content can be loaded automatically each time you scroll to the end of the existing content, or it can be triggered to load by clicking a navigation link at the end of the existing content.
An example of infinite scrolling is your Facebook "News Feed" page. You may notice that when you scroll to the bottom of this page, new content will often load automatically, or you will be given a link to "Older Posts" which will load more content when clicked.
The latest version of jScroll is available for download from GitHub.
The jscroll
method is called on the selector for which you want your scrollable content contained within. For example:
$('.infinite-scroll').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.
$('.infinite-scroll').jscroll({ loadingHtml: '<img src="loading.gif" alt="Loading" /> Loading...', padding: 20, nextSelector: 'a.jscroll-next:last', contentSelector: 'li' });
Option Key | Default Value | Description |
---|---|---|
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 great 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. |
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. |
callback | false | Pass a function to this option and it will be called at the end of each page load. Alternatively, you can pass a function as the only argument to the jScroll instantiation instead of an options object, and it will be returned as a callback. |
For more information on the contentSelector option and how it loads a response fragment, see the jQuery documentation for the .load() method.
For a real-world example of jScroll, visit Hang3 | Social Classifieds.
The following is an example of jScroll out of the box, using all default options.
Note: An additional page load time has been intentionally added for each scroll request so that you may more easily observe what is happening in the examples.
This is the content of page 1 in the jScroll example. Scroll to the bottom of this box to load the next set of content.
This is example text for the jScroll demonstration. jScroll is a jQuery plugin for infinite scrolling, endless scrolling, lazy loading, auto-paging, or whatever you may call it.
With jScroll, you can initialize the scroller on an element with a fixed height and overflow setting of "auto" or "scroll," or it can be set on a standard block-level element within the document and the scrolling will be initialized based on the brower window's scroll position.
jScroll is open-source and can be downloaded from my GitHub repository at github.com/pklauzinski/jscroll.
<div class="scroll"> <h3>Page 1</h3> <p>Content here...</p> <a href="example-page2.html">next page</a> </div>
$('.scroll').jscroll();
It's that easy!
autoTrigger = false
// Don't automatically load content on scroll, require user to click the link instead $('.scroll').jscroll({ autoTrigger: false });
This is the content of page 1 in the jScroll example. Scroll to the bottom of this box to load the next set of content.
This is example text for the jScroll demonstration. jScroll is a jQuery plugin for infinite scrolling, endless scrolling, lazy loading, auto-paging, or whatever you may call it.
With jScroll, you can initialize the scroller on an element with a fixed height and overflow setting of "auto" or "scroll," or it can be set on a standard block-level element within the document and the scrolling will be initialized based on the brower window's scroll position.
jScroll is open-source and can be downloaded from my GitHub repository at github.com/pklauzinski/jscroll.
autoTriggerUntil
// autoTrigger on scroll until after the third request is loaded $('.scroll').jscroll({ autoTriggerUntil: 3 });
This is the content of page 1 in the jScroll example. Scroll to the bottom of this box to load the next set of content.
This is example text for the jScroll demonstration. jScroll is a jQuery plugin for infinite scrolling, endless scrolling, lazy loading, auto-paging, or whatever you may call it.
With jScroll, you can initialize the scroller on an element with a fixed height and overflow setting of "auto" or "scroll," or it can be set on a standard block-level element within the document and the scrolling will be initialized based on the brower window's scroll position.
jScroll is open-source and can be downloaded from my GitHub repository at github.com/pklauzinski/jscroll.
jScroll is © 2016 Philip Klauzinski and dual licensed under the MIT and GPL Version 2 licenses.