forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll.ts
More file actions
118 lines (105 loc) · 2.85 KB
/
scroll.ts
File metadata and controls
118 lines (105 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { ChangeDetectionStrategy, Component, ElementRef, Input, ViewEncapsulation } from '@angular/core';
import { isTrueProperty } from '../../util/util';
/**
* @name Scroll
* @description
* Scroll is a non-flexboxed scroll area that can scroll horizontally or vertically. `ion-Scroll` Can be used in places where you may not need a full page scroller, but a highly customized one, such as image scubber or comment scroller.
* @usage
* ```html
* <ion-scroll scrollX="true">
* </ion-scroll>
*
* <ion-scroll scrollY="true">
* </ion-scroll>
*
* <ion-scroll scrollX="true" scrollY="true">
* </ion-scroll>
* ```
* @property {boolean} [scrollX] - whether to enable scrolling along the X axis
* @property {boolean} [scrollY] - whether to enable scrolling along the Y axis; requires the following CSS declaration: ion-scroll { white-space: nowrap; }
* @property {boolean} [zoom] - whether to enable zooming
* @property {number} [maxZoom] - set the max zoom amount for ion-scroll
* @demo /docs/v2/demos/src/scroll/
*/
@Component({
selector: 'ion-scroll',
template:
'<div class="scroll-content">' +
'<div class="scroll-zoom-wrapper">' +
'<ng-content></ng-content>' +
'</div>' +
'</div>',
host: {
'[class.scroll-x]': 'scrollX',
'[class.scroll-y]': 'scrollY'
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
})
export class Scroll {
_scrollX: boolean = false;
_scrollY: boolean = false;
_zoom: boolean = false;
_maxZoom: number = 1;
@Input()
get scrollX() {
return this._scrollX;
}
set scrollX(val: any) {
this._scrollX = isTrueProperty(val);
}
@Input()
get scrollY() {
return this._scrollY;
}
set scrollY(val: any) {
this._scrollY = isTrueProperty(val);
}
@Input()
get zoom() {
return this._zoom;
}
set zoom(val: any) {
this._zoom = isTrueProperty(val);
}
@Input()
get maxZoom() {
return this._maxZoom;
}
set maxZoom(val: any) {
this._maxZoom = val;
}
/**
* @private
*/
maxScale: number = 3;
/**
* @private
*/
zoomDuration: number = 250;
/**
* @private
*/
scrollElement: HTMLElement;
constructor(private _elementRef: ElementRef) {}
/**
* @private
*/
ngOnInit() {
this.scrollElement = this._elementRef.nativeElement.children[0];
}
/**
* @private
* Add a scroll event handler to the scroll element if it exists.
* @param {Function} handler The scroll handler to add to the scroll element.
* @returns {?Function} a function to remove the specified handler, otherwise
* undefined if the scroll element doesn't exist.
*/
addScrollEventListener(handler: any) {
if (!this.scrollElement) { return; }
this.scrollElement.addEventListener('scroll', handler);
return () => {
this.scrollElement.removeEventListener('scroll', handler);
};
}
}