-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
sweet-scroll.d.ts
179 lines (172 loc) · 6.53 KB
/
sweet-scroll.d.ts
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Generated by dts-bundle v0.7.3
declare module 'sweet-scroll' {
import { RequestAnimationFrame, CancelAnimationFrame } from 'sweet-scroll/decls/animation/requestAnimationFrame';
import { EasingFunction } from 'sweet-scroll/decls/animation/easings';
import { Offset } from 'sweet-scroll/decls/dom/offsets';
import { Options, PartialOptions } from 'sweet-scroll/decls/options';
import { ScrollableElement } from 'sweet-scroll/decls/types';
export { Options, PartialOptions, EasingFunction, Offset, RequestAnimationFrame, CancelAnimationFrame, };
export default class SweetScroll {
/**
* You can set Polyfill (or Ponyfill) for browsers that do not support requestAnimationFrame.
*/
static raf: RequestAnimationFrame;
static caf: CancelAnimationFrame;
/**
* SweetScroll instance factory.
*/
static create(options?: PartialOptions, container?: string | ScrollableElement): SweetScroll;
/**
* Constructor
*/
constructor(options?: PartialOptions, container?: string | ScrollableElement);
/**
* Scroll animation to the specified position.
*/
to(distance: any, options?: PartialOptions): void;
/**
* Scroll animation to specified left position.
*/
toTop(distance: any, options?: PartialOptions): void;
/**
* Scroll animation to specified top position.
*/
toLeft(distance: any, options?: PartialOptions): void;
/**
* Scroll animation to specified element.
*/
toElement($element: Element, options?: PartialOptions): void;
/**
* Stop the current scroll animation.
*/
stop(gotoEnd?: boolean): void;
/**
* Update options.
*/
update(options: PartialOptions): void;
/**
* Destroy instance.
*/
destroy(): void;
/**
* Callback methods.
*/
protected onBefore(_: Offset, __: Element | null): boolean | void;
protected onStep(_: number): void;
protected onAfter(_: Offset, __: Element | null): void;
protected onCancel(): void;
protected onComplete(_: boolean): void;
/**
* Start scrolling animation.
*/
protected start(opts: Options): void;
/**
* Handle each frame of the animation.
*/
protected loop: (time: number) => void;
/**
* Handle the completion of scrolling animation.
*/
protected complete(): void;
/**
* Callback function and method call.
*/
protected hook(options: Options, type: 'before' | 'after' | 'step' | 'cancel' | 'complete', ...args: any[]): any;
/**
* Bind events of container element.
*/
protected bind(click: boolean, stop: boolean): void;
/**
* Unbind events of container element.
*/
protected unbind(click: boolean, stop: boolean): void;
/**
* Handling of container click event.
*/
protected handleClick: (e: Event) => void;
/**
* Handling of container stop events.
*/
protected handleStop: (e: Event) => void;
}
}
declare module 'sweet-scroll/decls/animation/requestAnimationFrame' {
export interface RequestAnimationFrame {
(callback: (time: number) => void): number;
}
export interface CancelAnimationFrame {
(handle: number): void;
}
export const raf: RequestAnimationFrame;
export const caf: CancelAnimationFrame;
}
declare module 'sweet-scroll/decls/animation/easings' {
export interface EasingFunction {
(x: number, t: number, b: number, c: number, d: number, s?: number): number;
}
export interface Easings {
[name: string]: EasingFunction;
}
export const easings: Easings;
}
declare module 'sweet-scroll/decls/dom/offsets' {
import { ScrollableElement } from 'sweet-scroll/decls/types';
export interface Offset {
top: number;
left: number;
}
export type Direction = 'x' | 'y';
export const directionMethodMap: {
[P in Direction]: 'scrollTop' | 'scrollLeft';
};
export const directionPropMap: {
[P in Direction]: 'pageXOffset' | 'pageYOffset';
};
export const getScroll: ($el: ScrollableElement, direction: Direction) => number;
export const setScroll: ($el: ScrollableElement, offset: number, direction: Direction) => void;
export const getOffset: ($el: Element, $context: ScrollableElement) => Offset;
}
declare module 'sweet-scroll/decls/options' {
import { EasingFunction } from 'sweet-scroll/decls/animation/easings';
import { Offset } from 'sweet-scroll/decls/dom/offsets';
import SweetScroll from 'sweet-scroll/decls/index';
export interface BeforeHandler {
(offset: Offset, $trigger: Element | null, scroller: SweetScroll): boolean | void;
}
export interface AfterHandler {
(offset: Offset, $trigger: Element | null, scroller: SweetScroll): void;
}
export interface StepHandler {
(time: number, scroller: SweetScroll): void;
}
export interface CancelHandler {
(scroller: SweetScroll): void;
}
export interface CompleteHandler {
(isCancel: boolean, scroller: SweetScroll): void;
}
export interface Options {
trigger: string;
header: string | Element;
duration: number;
easing: string | EasingFunction;
offset: number;
vertical: boolean;
horizontal: boolean;
cancellable: boolean;
updateURL: boolean | string;
preventDefault: boolean;
stopPropagation: boolean;
before: BeforeHandler | null;
after: AfterHandler | null;
step: StepHandler | null;
cancel: CancelHandler | null;
complete: CompleteHandler | null;
}
export interface PartialOptions extends Partial<Options> {
}
export const defaultOptions: Options;
}
declare module 'sweet-scroll/decls/types' {
export type ScrollableElement = Element | Window;
}