msforest / notebook

好记性不如烂笔头,记录知识的点点滴滴。
https://github.com/msforest/notebook/wiki
0 stars 0 forks source link

IScroll & ngInfiniteScroll #7

Open msforest opened 7 years ago

msforest commented 7 years ago

1. IScroll

2. ngInfiniteScroll

iscroll用法

推荐使用的html格式

<div id="wrapper">
    <ul>
        <li>...</li>
        <li>...</li>
        ...
    </ul>
</div>

js初始化iscroll对象,有三种方式如下:

iscroll事件

通过scroll的on方法来注册事件

myScroll = new IScroll('#wrapper'); myScroll.on('scrollEnd', doSomething);

msforest commented 7 years ago

移动Web滚动性能优化: Passive event listeners

function isPassive() {
    var supportsPassiveOption = false;
    try {
        addEventListener("test", null, Object.defineProperty({}, 'passive', {
            get: function () {
                supportsPassiveOption = true;
            }
        }));
    } catch(e) {}
    return supportsPassiveOption;
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, isPassive() ? {
    capture: false,
    passive: false
} : false);

使用以上代码可以启用手机端页面的touchmove事件

msforest commented 7 years ago

ngInfiniteScroll

ngInfiniteScrollIScroll都是实现滑动加载数据,一个是指令实现,一个是组件实现,指令实现的虽没有组件实现的各种特效,但是相比之下,在angular中使用IScroll有点重。下面了解一下ngInfiniteScroll的用法。

infiniteScroll:当滑动到底部的时候,可以指定函数实现数据再加载。

语法

<ANY infinite-scroll='{expression}'
     [infinite-scroll-distance='{number}']
     [infinite-scroll-disabled='{boolean}']
     [infinite-scroll-immediate-check='{boolean}']
     [infinite-scroll-listen-for-event='{string}']
     [infinite-scroll-container='{HTMLElement | [] | string}']
     [infinite-scroll-use-document-bottom='{boolean}']
     [infinite-scroll-parent]>
</ANY>

模块加载

var myApp = angular.module('myApp', ['infinite-scroll']);

函数节流

angular.module('infinite-scroll').value('THROTTLE_MILLISECONDS', 250)

手动触发事件

使用infinite-scroll-listen-for-event定义触发事件

<div infinite-scroll="addMoreItems()" infinite-scroll-listen-for-event="list:filtered">
  [...]
</div>

当需要触发自定义的事件时,使用$scope.$emit('list:filtered')

指令用法

<div infinite-scroll="addMoreItems()">
  <div ng-repeat="item in items">Item number {{$index}}: {{$item}}</div>
</div>