转 js Infinite Scrolling Demo

原文:http://www.sitepoint.com/jquery-infinite-scrolling-demos/

Infinite Scrolling Demo 5

Usage – HTML

<ul class="items">
   <li>content</li>
   <li>content</li>
   ...
</ul>
<div id="lastPostsLoader"></div>

Usage – jQuery

<script type="text/javascript">
$(document).ready(function(){
    function lastAddedLiveFunc()
    {
        $(‘div#lastPostsLoader‘).html(‘<img src="bigLoader.gif"/>‘);

        $.get("loadmore.php", function(data){
            if (data != "") {
                //console.log(‘add data..‘);
                $(".items").append(data);
            }
            $(‘div#lastPostsLoader‘).empty();
        });
    };

    //lastAddedLiveFunc();
    $(window).scroll(function(){

        var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
        var  scrolltrigger = 0.95;

        if  ((wintop/(docheight-winheight)) > scrolltrigger) {
         //console.log(‘scroll bottom‘);
         lastAddedLiveFunc();
        }
    });
});
</script>

Infinite Scrolling Demo 3

This demo loads in images on infinite scroll and never reaches the end. It uses the jquery.endless-scroll plugin which can be customised to trigger load for x number of pixels from the bottom of the screen. The demo clones the same images and inserts them at the end of the list and so on. Obviously the script can be customised to load more images from different sources quite easily

Usage – HTML

<ul id="images">
  <li><img src="img/grass-blades.jpg" width="580" height="360" alt="Grass Blades" /></li>
  <li><img src="img/stones.jpg" width="580" height="360" alt="Stones" /></li>
  <li><img src="img/sea-mist.jpg" width="580" height="360" alt="Sea Mist" /></li>
  <li><img src="img/pier.jpg" width="580" height="360" alt="Pier" /></li>
  <li><img src="img/lotus.jpg" width="580" height="360" alt="Lotus" /></li>
  <li><img src="img/mojave.jpg" width="580" height="360" alt="Mojave" /></li>
  <li><img src="img/lightning.jpg" width="580" height="360" alt="Lightning" /></li>
</ul>

Usage – jQuery

<script type="text/javascript" src="js/jquery.endless-scroll.js"></script>
<script type="text/javascript" charset="utf-8">
  $(function() {
    $(document).endlessScroll({
      bottomPixels: 500,
      fireDelay: 10,
      callback: function(i) {
        var last_img = $("ul#images li:last");
        last_img.after(last_img.prev().prev().prev().prev().prev().prev().clone());
      }
    });
  });
</script>
var end = $("#BottomThing").offset().top;
var viewEnd = $(window).scrollTop() + $(window).height();
var distance = end - viewEnd;
if (distance < 300) // do load –  
时间: 2024-08-07 21:20:51

转 js Infinite Scrolling Demo的相关文章

微信JS SDK PHP Demo

一.JSSDK类定义 <?php class JSSDK { private $appId; private $appSecret; public function __construct($appId, $appSecret) { $this->appId = $appId; $this->appSecret = $appSecret; } public function getSignPackage() { $jsapiTicket = $this->getJsApiTicke

js 插件学习demo

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><script src="js/jquery-1.11.3

RSA JS 加密解密DEMO

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="Scripts/jQuery.md5.js" type="text/javascript" ></script> <script src="Scripts/BigInt.js" type=

jcFlexible.js的小Demo

;(function(win, lib) { var doc = win.document; var docEl = doc.documentElement; var metaEl = doc.querySelector('meta[name="viewport"]'); var flexibleEl = doc.querySelector('meta[name="flexible"]'); var dpr = 0; var scale = 0; var tid;

XLSX.js 导出Excel demo

GitHub:https://github.com/SheetJS/js-xlsx 一个js操作Excel的工具,如下代码,很方便的就将json数据导出为Excel文件. 使用示例: //json 数据 var data = [{ "a": 1, "x": 2, "b": 3, "y": 4, "success":true }, { "a": 1, "x": 2, &

ORACLE JET Basic Table Infinite Scrolling

Basic Table例子:Basic Table

JS杂谈系列-函数知识、函数模式

函数,函数,function,function,go go go! 创建函数: 第一种:function aa(){alert(1)}; 第二种:var aa=function(){alert(1)}; 其实对于使用没有太大的区别,第一个是用函数关键字创建,第二个是创建变量,然后赋值为一个函数. 同样我们还可以创建匿名函数 function(){alert(1)}; 函数的里面可以传递参数arg function aa(arg){alert(arg)}; function aa(arg1,arg

微信公众平台开发(103) JS API支付

本文介绍如何使用JS API支付接口完成微信支付. 一.JS API支付接口(getBrandWCPayRequest) 微信JS API只能在微信内置浏览器中使用,其他浏览器调用无效.微信提供getBrandWCPayRequest接口供商户前端网页调用,调用之前微信会鉴定商户支付权限,若商户具有调起支付的权限,则将开始支付流程.这里主要介绍支付前的接口调用规则,支付状态消息通知机制请参加下文.接口需要注意:所有传入参数都是字符串类型! getBrandWCPayRequest参数如表6-5所

Vue.js小案例(2)

即时搜索 这个例子主要应用了vue.js的自定义过滤器,可以通过Vue.filter()注册一个全局过滤器,具体用法可以参考这里,vue.js也提供了一些内置过滤器. CSS代码: [v-cloak] { display: none; } *{ margin:0; padding:0; } body{ font-family:Microsoft YaHei; text-align:center; } li{ list-style:none; } .bar{ background-color:#5