jQuery: jScroll 下拉加载更多

About jScroll

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.

 

Download Latest Version

The latest version of jScroll is available for download from GitHub.

 

Usage

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'
});

 

Options

Option KeyDefault ValueDescription
debugfalseWhen set to true, outputs useful information to the console display if theconsole object exists.
autoTriggertrueWhen 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.
autoTriggerUntilfalseSet to an integer great than 0 to turn offautoTrigger 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.
padding0The 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 hrefattribute, 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.
callbackfalsePass 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.

 

Example 1

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.

 

The HTML (abbreviated)

<div class="scroll">
    <h3>Page 1</h3>
    <p>Content here...</p>
    <a href="example-page2.html">next page</a>
</div>

 

The JavaScript

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

 

It's that easy!

 

Example 2 - Using autoTrigger = false

// Don't automatically load content on scroll, require user to click the link instead
$('.scroll').jscroll({
    autoTrigger: false
});

 

Example 3 - Using autoTriggerUntil

// autoTrigger on scroll until after the third request is loaded
$('.scroll').jscroll({
    autoTriggerUntil: 3
});

 

 

原文:http://jscroll.com/

下载:jscroll-master

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值