本文整理匯總了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);
});
示例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]);
});
});
示例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]);
});