本文整理汇总了TypeScript中app/shared/scroll-spy.service.ScrollSpiedElementGroup类的典型用法代码示例。如果您正苦于以下问题:TypeScript service.ScrollSpiedElementGroup类的具体用法?TypeScript service.ScrollSpiedElementGroup怎么用?TypeScript service.ScrollSpiedElementGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了service.ScrollSpiedElementGroup类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
const tops = [50, 150, 100];
spyOn(ScrollSpiedElement.prototype, 'calculateTop').and.callFake(function(scrollTop, topOffset) {
this.top = tops[this.index];
});
activeItems = [];
group = new ScrollSpiedElementGroup([{}, {}, {}] as Element[]);
group.activeScrollItem.subscribe(item => activeItems.push(item));
group.calibrate(20, 10);
});
开发者ID:DanielKucal,项目名称:angular,代码行数:12,代码来源:scroll-spy.service.spec.ts
示例2: describe
describe('#onScroll()', () => {
let group: ScrollSpiedElementGroup;
let activeItems: (ScrollItem|null)[];
const activeIndices = () => activeItems.map(x => x && x.index);
beforeEach(() => {
const tops = [50, 150, 100];
spyOn(ScrollSpiedElement.prototype, 'calculateTop').and.callFake(
function(this: ScrollSpiedElement, scrollTop: number, topOffset: number) {
this.top = tops[this.index];
});
activeItems = [];
group = new ScrollSpiedElementGroup([{}, {}, {}] as Element[]);
group.activeScrollItem.subscribe(item => activeItems.push(item));
group.calibrate(20, 10);
});
it('should emit a `ScrollItem` on `activeScrollItem`', () => {
expect(activeItems.length).toBe(0);
group.onScroll(20, 140);
expect(activeItems.length).toBe(1);
group.onScroll(20, 140);
expect(activeItems.length).toBe(2);
});
it('should emit the lower-most element that is above `scrollTop`', () => {
group.onScroll(45, 200);
group.onScroll(55, 200);
expect(activeIndices()).toEqual([null, 0]);
activeItems.length = 0;
group.onScroll(95, 200);
group.onScroll(105, 200);
expect(activeIndices()).toEqual([0, 2]);
activeItems.length = 0;
group.onScroll(145, 200);
group.onScroll(155, 200);
expect(activeIndices()).toEqual([2, 1]);
activeItems.length = 0;
group.onScroll(75, 200);
group.onScroll(175, 200);
group.onScroll(125, 200);
group.onScroll(25, 200);
expect(activeIndices()).toEqual([0, 1, 2, null]);
});
it('should always emit the lower-most element if scrolled to the bottom', () => {
group.onScroll(140, 140);
group.onScroll(145, 140);
group.onScroll(138.5, 140);
group.onScroll(139.5, 140);
expect(activeIndices()).toEqual([1, 1, 2, 1]);
});
it('should emit null if all elements are below `scrollTop`', () => {
group.onScroll(0, 140);
expect(activeItems).toEqual([null]);
group.onScroll(49, 140);
expect(activeItems).toEqual([null, null]);
});
it('should emit null if there are no spied elements (even if scrolled to the bottom)', () => {
group = new ScrollSpiedElementGroup([]);
group.activeScrollItem.subscribe(item => activeItems.push(item));
group.onScroll(20, 140);
expect(activeItems).toEqual([null]);
group.onScroll(140, 140);
expect(activeItems).toEqual([null, null]);
group.onScroll(145, 140);
expect(activeItems).toEqual([null, null, null]);
});
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:85,代码来源:scroll-spy.service.spec.ts
示例3: it
it('should emit null if all elements are below `scrollTop`', () => {
group.onScroll(0, 140);
expect(activeItems).toEqual([null]);
group.onScroll(49, 140);
expect(activeItems).toEqual([null, null]);
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:7,代码来源:scroll-spy.service.spec.ts
注:本文中的app/shared/scroll-spy.service.ScrollSpiedElementGroup类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论