Open msforest opened 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事件
ngInfiniteScroll
和IScroll
都是实现滑动加载数据,一个是指令实现,一个是组件实现,指令实现的虽没有组件实现的各种特效,但是相比之下,在angular中使用IScroll有点重。下面了解一下ngInfiniteScroll
的用法。
<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>
1. IScroll
2. ngInfiniteScroll
iscroll用法
推荐使用的html格式
js初始化iscroll对象,有三种方式如下:
iscroll可选参数配置
初始化时给第二个参数传递一个对象
iscroll事件
通过scroll的on方法来注册事件