@egjs/flicking-plugins 4.8.0-beta.1 → 4.8.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -51
- package/css/all.css +2 -0
- package/css/arrow.css +2 -2
- package/css/pagination.css +5 -3
- package/declaration/Arrow.d.ts +106 -51
- package/declaration/AutoPlay.d.ts +104 -44
- package/declaration/Fade.d.ts +41 -16
- package/declaration/Parallax.d.ts +41 -16
- package/declaration/Perspective.d.ts +71 -28
- package/declaration/Sync.d.ts +93 -37
- package/declaration/const.d.ts +31 -31
- package/declaration/event.d.ts +5 -5
- package/declaration/index.d.ts +13 -10
- package/declaration/pagination/Pagination.d.ts +141 -61
- package/declaration/pagination/index.d.ts +3 -3
- package/declaration/pagination/renderer/BulletRenderer.d.ts +11 -11
- package/declaration/pagination/renderer/FractionRenderer.d.ts +9 -9
- package/declaration/pagination/renderer/Renderer.d.ts +19 -19
- package/declaration/pagination/renderer/ScrollBulletRenderer.d.ts +12 -12
- package/declaration/tsdoc-metadata.json +11 -0
- package/declaration/type.d.ts +9 -9
- package/declaration/utils.d.ts +3 -3
- package/dist/arrow.css +2 -2
- package/dist/flicking-plugins.css +23 -8
- package/dist/flicking-plugins.min.css +1 -1
- package/dist/pagination.css +21 -6
- package/dist/pagination.min.css +1 -1
- package/dist/plugins.esm.js +1030 -1591
- package/dist/plugins.esm.js.map +1 -1
- package/dist/plugins.js +1047 -1620
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.min.js +1 -9
- package/dist/plugins.min.js.map +1 -1
- package/package.json +49 -105
- package/src/Arrow.ts +133 -82
- package/src/AutoPlay.ts +105 -35
- package/src/Fade.ts +31 -11
- package/src/Parallax.ts +31 -11
- package/src/Perspective.ts +69 -22
- package/src/Sync.ts +69 -25
- package/src/index.ts +9 -22
- package/src/pagination/Pagination.ts +163 -40
- package/src/pagination/index.ts +2 -6
- package/src/pagination/renderer/BulletRenderer.ts +1 -4
- package/src/pagination/renderer/FractionRenderer.ts +1 -3
- package/src/pagination/renderer/Renderer.ts +14 -13
- package/src/pagination/renderer/ScrollBulletRenderer.ts +5 -12
- package/CONTRIBUTING +0 -58
- package/rollup.config.dev.js +0 -17
- package/rollup.config.js +0 -33
- package/tsconfig.declaration.json +0 -10
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -17
- package/tsconfig.test.json +0 -21
package/src/AutoPlay.ts
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
|
-
import Flicking, {
|
|
1
|
+
import Flicking, { DIRECTION, EVENTS, MOVE_TYPE, Plugin } from "@egjs/flicking";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Options for the {@link AutoPlay} plugin
|
|
5
|
+
*/
|
|
6
|
+
export interface AutoPlayOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Time to wait before moving on to the next panel (ms)
|
|
9
|
+
* @defaultValue 2000
|
|
10
|
+
*/
|
|
4
11
|
duration: number;
|
|
12
|
+
/**
|
|
13
|
+
* Duration of the panel move animation (ms). If `undefined`, the Flicking instance's `duration` is used
|
|
14
|
+
* @defaultValue undefined
|
|
15
|
+
*/
|
|
5
16
|
animationDuration: number | undefined;
|
|
6
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The direction in which the panel moves
|
|
19
|
+
* @defaultValue "NEXT"
|
|
20
|
+
*/
|
|
21
|
+
direction: (typeof DIRECTION)["NEXT"] | (typeof DIRECTION)["PREV"];
|
|
22
|
+
/**
|
|
23
|
+
* Whether to stop when the mouse hovers over the element
|
|
24
|
+
* @defaultValue false
|
|
25
|
+
*/
|
|
7
26
|
stopOnHover: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to stop autoplay when the plugin is first initialized
|
|
29
|
+
* @defaultValue false
|
|
30
|
+
*/
|
|
8
31
|
stopOnInit: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If `stopOnHover` is true, time to wait before resuming after mouse leaves (ms)
|
|
34
|
+
* @defaultValue Same as `duration`
|
|
35
|
+
*/
|
|
9
36
|
delayAfterHover: number;
|
|
10
37
|
}
|
|
11
38
|
|
|
12
39
|
/**
|
|
13
|
-
* Plugin that
|
|
14
|
-
* @
|
|
15
|
-
* @memberof Flicking.Plugins
|
|
40
|
+
* Plugin that allows you to automatically move to the next/previous panel on a specific time basis
|
|
41
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/autoplay | Demo: AutoPlay}
|
|
16
42
|
*/
|
|
17
43
|
class AutoPlay implements Plugin {
|
|
18
44
|
/* Options */
|
|
@@ -29,42 +55,79 @@ class AutoPlay implements Plugin {
|
|
|
29
55
|
private _mouseEntered = false;
|
|
30
56
|
private _playing = false;
|
|
31
57
|
|
|
32
|
-
|
|
33
|
-
public get
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
public get
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
public
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
public
|
|
58
|
+
/** Current value of the {@link AutoPlayOptions.duration | duration} option. */
|
|
59
|
+
public get duration() {
|
|
60
|
+
return this._duration;
|
|
61
|
+
}
|
|
62
|
+
/** Current value of the {@link AutoPlayOptions.animationDuration | animationDuration} option. */
|
|
63
|
+
public get animationDuration() {
|
|
64
|
+
return this._animationDuration;
|
|
65
|
+
}
|
|
66
|
+
/** Current value of the {@link AutoPlayOptions.direction | direction} option. */
|
|
67
|
+
public get direction() {
|
|
68
|
+
return this._direction;
|
|
69
|
+
}
|
|
70
|
+
/** Current value of the {@link AutoPlayOptions.stopOnHover | stopOnHover} option. */
|
|
71
|
+
public get stopOnHover() {
|
|
72
|
+
return this._stopOnHover;
|
|
73
|
+
}
|
|
74
|
+
/** Current value of the {@link AutoPlayOptions.stopOnInit | stopOnInit} option. */
|
|
75
|
+
public get stopOnInit() {
|
|
76
|
+
return this._stopOnInit;
|
|
77
|
+
}
|
|
78
|
+
/** Current value of the {@link AutoPlayOptions.delayAfterHover | delayAfterHover} option. */
|
|
79
|
+
public get delayAfterHover() {
|
|
80
|
+
return this._delayAfterHover;
|
|
81
|
+
}
|
|
82
|
+
/** Whether the autoplay is currently active
|
|
83
|
+
* @readonly
|
|
84
|
+
*/
|
|
85
|
+
public get playing() {
|
|
86
|
+
return this._playing;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Sets {@link AutoPlayOptions.duration | duration}. */
|
|
90
|
+
public set duration(val: number) {
|
|
91
|
+
this._duration = val;
|
|
92
|
+
}
|
|
93
|
+
/** Sets {@link AutoPlayOptions.animationDuration | animationDuration}. */
|
|
94
|
+
public set animationDuration(val: number | undefined) {
|
|
95
|
+
this._animationDuration = val;
|
|
96
|
+
}
|
|
97
|
+
/** Sets {@link AutoPlayOptions.direction | direction}. */
|
|
98
|
+
public set direction(val: AutoPlayOptions["direction"]) {
|
|
99
|
+
this._direction = val;
|
|
100
|
+
}
|
|
101
|
+
/** Sets {@link AutoPlayOptions.stopOnHover | stopOnHover}. */
|
|
102
|
+
public set stopOnHover(val: boolean) {
|
|
103
|
+
this._stopOnHover = val;
|
|
104
|
+
}
|
|
105
|
+
/** Sets {@link AutoPlayOptions.stopOnInit | stopOnInit}. */
|
|
106
|
+
public set stopOnInit(val: boolean) {
|
|
107
|
+
this._stopOnInit = val;
|
|
108
|
+
}
|
|
109
|
+
/** Sets {@link AutoPlayOptions.delayAfterHover | delayAfterHover}. */
|
|
110
|
+
public set delayAfterHover(val: number) {
|
|
111
|
+
this._delayAfterHover = val;
|
|
112
|
+
}
|
|
46
113
|
|
|
47
114
|
/**
|
|
48
|
-
* @param
|
|
49
|
-
* @param {number} options.duration Time to wait before moving on to the next panel.<ko>다음 패널로 움직이기까지 대기 시간</ko>
|
|
50
|
-
* @param {number | undefined} options.animationDuration Duration of animation of moving to the next panel. If undefined, duration option of the Flicking instance is used instead.<ko>패널이 움직이는 애니메이션의 지속 시간, undefined라면 Flicking 인스턴스의 duration 값을 사용한다</ko>
|
|
51
|
-
* @param {"PREV" | "NEXT"} options.direction The direction in which the panel moves.<ko>패널이 움직이는 방향</ko>
|
|
52
|
-
* @param {boolean} options.stopOnHover Whether to stop when mouse hover upon the element.<ko>엘리먼트에 마우스를 올렸을 때 AutoPlay를 정지할지 여부</ko>
|
|
53
|
-
* @param {boolean} options.stopOnInit Whether to stop when mouse hover upon the element.<ko>엘리먼트에 마우스를 올렸을 때 AutoPlay를 정지할지 여부</ko>
|
|
54
|
-
* @param {number} options.delayAfterHover If stopOnHover is true, the amount of time to wait before moving on to the next panel when mouse leaves the element.<ko>stopOnHover를 사용한다면 마우스가 엘리먼트로부터 나간 뒤 다음 패널로 움직이기까지 대기 시간</ko>
|
|
115
|
+
* @param options - Options for the AutoPlay instance
|
|
55
116
|
* @example
|
|
56
117
|
* ```ts
|
|
57
118
|
* flicking.addPlugins(new AutoPlay({ duration: 2000, direction: "NEXT" }));
|
|
58
119
|
* ```
|
|
59
120
|
*/
|
|
60
|
-
public constructor({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
121
|
+
public constructor(options: Partial<AutoPlayOptions> = {}) {
|
|
122
|
+
const {
|
|
123
|
+
duration = 2000,
|
|
124
|
+
animationDuration = undefined,
|
|
125
|
+
direction = DIRECTION.NEXT,
|
|
126
|
+
stopOnHover = false,
|
|
127
|
+
stopOnInit = false,
|
|
128
|
+
delayAfterHover
|
|
129
|
+
} = options;
|
|
130
|
+
|
|
68
131
|
this._duration = duration;
|
|
69
132
|
this._animationDuration = animationDuration;
|
|
70
133
|
this._direction = direction;
|
|
@@ -73,6 +136,9 @@ class AutoPlay implements Plugin {
|
|
|
73
136
|
this._delayAfterHover = delayAfterHover ?? duration;
|
|
74
137
|
}
|
|
75
138
|
|
|
139
|
+
/** Initialize the plugin and start autoplay on the given Flicking instance.
|
|
140
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
141
|
+
*/
|
|
76
142
|
public init(flicking: Flicking): void {
|
|
77
143
|
if (this._flicking) {
|
|
78
144
|
this.destroy();
|
|
@@ -97,6 +163,7 @@ class AutoPlay implements Plugin {
|
|
|
97
163
|
}
|
|
98
164
|
}
|
|
99
165
|
|
|
166
|
+
/** Destroy the plugin, stop autoplay, and remove all event listeners. */
|
|
100
167
|
public destroy(): void {
|
|
101
168
|
const flicking = this._flicking;
|
|
102
169
|
|
|
@@ -119,14 +186,17 @@ class AutoPlay implements Plugin {
|
|
|
119
186
|
this._flicking = null;
|
|
120
187
|
}
|
|
121
188
|
|
|
189
|
+
/** Update the plugin state. This is a no-op for AutoPlay. */
|
|
122
190
|
public update(): void {
|
|
123
191
|
// DO-NOTHING
|
|
124
192
|
}
|
|
125
193
|
|
|
194
|
+
/** Start the autoplay timer. Panels will move automatically after the configured {@link AutoPlayOptions.duration | duration}. */
|
|
126
195
|
public play = () => {
|
|
127
196
|
this._movePanel(this._duration);
|
|
128
197
|
};
|
|
129
198
|
|
|
199
|
+
/** Stop the autoplay timer and cancel any pending panel movement. */
|
|
130
200
|
public stop = () => {
|
|
131
201
|
this._playing = false;
|
|
132
202
|
clearTimeout(this._timerId);
|
package/src/Fade.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Flicking, { EVENTS, Plugin } from "@egjs/flicking";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @memberof Flicking.Plugins
|
|
4
|
+
* A plugin to apply fade in/out effect while panels are moving
|
|
5
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/fade | Demo: Fade}
|
|
7
6
|
*/
|
|
8
7
|
class Fade implements Plugin {
|
|
9
8
|
private _flicking: Flicking | null;
|
|
@@ -12,15 +11,31 @@ class Fade implements Plugin {
|
|
|
12
11
|
private _selector: string;
|
|
13
12
|
private _scale: number;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/** CSS selector for the element to apply the fade effect. If empty, the panel element itself is used
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
public get selector() {
|
|
18
|
+
return this._selector;
|
|
19
|
+
}
|
|
20
|
+
/** Effect amplification scale
|
|
21
|
+
* @readonly
|
|
22
|
+
*/
|
|
23
|
+
public get scale() {
|
|
24
|
+
return this._scale;
|
|
25
|
+
}
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
public set
|
|
27
|
+
/** Sets the CSS selector for the target fade element. */
|
|
28
|
+
public set selector(val: string) {
|
|
29
|
+
this._selector = val;
|
|
30
|
+
}
|
|
31
|
+
/** Sets the effect amplification scale. */
|
|
32
|
+
public set scale(val: number) {
|
|
33
|
+
this._scale = val;
|
|
34
|
+
}
|
|
20
35
|
|
|
21
36
|
/**
|
|
22
|
-
* @param -
|
|
23
|
-
* @param - Effect
|
|
37
|
+
* @param selector - CSS selector for the element to apply the fade effect. If empty, the panel element itself is used
|
|
38
|
+
* @param scale - Effect amplification scale
|
|
24
39
|
* @example
|
|
25
40
|
* ```ts
|
|
26
41
|
* flicking.addPlugins(new Fade("p", 1));
|
|
@@ -32,6 +47,9 @@ class Fade implements Plugin {
|
|
|
32
47
|
this._scale = scale;
|
|
33
48
|
}
|
|
34
49
|
|
|
50
|
+
/** Initialize the plugin and apply the fade effect to the Flicking instance.
|
|
51
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
52
|
+
*/
|
|
35
53
|
public init(flicking: Flicking): void {
|
|
36
54
|
if (this._flicking) {
|
|
37
55
|
this.destroy();
|
|
@@ -44,6 +62,7 @@ class Fade implements Plugin {
|
|
|
44
62
|
this._onMove();
|
|
45
63
|
}
|
|
46
64
|
|
|
65
|
+
/** Destroy the plugin and remove all event listeners. */
|
|
47
66
|
public destroy(): void {
|
|
48
67
|
if (!this._flicking) return;
|
|
49
68
|
|
|
@@ -52,6 +71,7 @@ class Fade implements Plugin {
|
|
|
52
71
|
this._flicking = null;
|
|
53
72
|
}
|
|
54
73
|
|
|
74
|
+
/** Recalculate and apply the fade effect to all visible panels. */
|
|
55
75
|
public update = (): void => {
|
|
56
76
|
this._onMove();
|
|
57
77
|
};
|
|
@@ -68,10 +88,10 @@ class Fade implements Plugin {
|
|
|
68
88
|
panels.forEach(panel => {
|
|
69
89
|
const progress = panel.outsetProgress;
|
|
70
90
|
const el = panel.element;
|
|
71
|
-
const target = selector ? el.querySelector
|
|
91
|
+
const target = selector ? (el.querySelector(selector) as HTMLElement) : el;
|
|
72
92
|
|
|
73
93
|
if (target) {
|
|
74
|
-
const opacity = Math.min(
|
|
94
|
+
const opacity = Math.min(1, Math.max(0, 1 - Math.abs(progress * scale)));
|
|
75
95
|
target.style.opacity = `${opacity}`;
|
|
76
96
|
}
|
|
77
97
|
});
|
package/src/Parallax.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Flicking, { EVENTS, Plugin } from "@egjs/flicking";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @memberof Flicking.Plugins
|
|
4
|
+
* A plugin to apply parallax effect while panels are moving
|
|
5
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/parallax | Demo: Parallax}
|
|
7
6
|
*/
|
|
8
7
|
class Parallax implements Plugin {
|
|
9
8
|
private _flicking: Flicking | null;
|
|
@@ -12,15 +11,31 @@ class Parallax implements Plugin {
|
|
|
12
11
|
private _selector: string;
|
|
13
12
|
private _scale: number;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/** CSS selector for the element to apply the parallax effect. If empty, the panel element itself is used
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
public get selector() {
|
|
18
|
+
return this._selector;
|
|
19
|
+
}
|
|
20
|
+
/** Effect amplification scale
|
|
21
|
+
* @readonly
|
|
22
|
+
*/
|
|
23
|
+
public get scale() {
|
|
24
|
+
return this._scale;
|
|
25
|
+
}
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
public set
|
|
27
|
+
/** Sets the CSS selector for the target parallax element. */
|
|
28
|
+
public set selector(val: string) {
|
|
29
|
+
this._selector = val;
|
|
30
|
+
}
|
|
31
|
+
/** Sets the effect amplification scale. */
|
|
32
|
+
public set scale(val: number) {
|
|
33
|
+
this._scale = val;
|
|
34
|
+
}
|
|
20
35
|
|
|
21
36
|
/**
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
37
|
+
* @param selector - CSS selector for the element to apply the parallax effect. If empty, the panel element itself is used
|
|
38
|
+
* @param scale - Effect amplification scale
|
|
24
39
|
* @example
|
|
25
40
|
* ```ts
|
|
26
41
|
* flicking.addPlugins(new Parallax("img", 1));
|
|
@@ -32,6 +47,9 @@ class Parallax implements Plugin {
|
|
|
32
47
|
this._scale = scale;
|
|
33
48
|
}
|
|
34
49
|
|
|
50
|
+
/** Initialize the plugin and apply the parallax effect to the Flicking instance.
|
|
51
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
52
|
+
*/
|
|
35
53
|
public init(flicking: Flicking): void {
|
|
36
54
|
if (this._flicking) {
|
|
37
55
|
this.destroy();
|
|
@@ -44,6 +62,7 @@ class Parallax implements Plugin {
|
|
|
44
62
|
this._onMove();
|
|
45
63
|
}
|
|
46
64
|
|
|
65
|
+
/** Destroy the plugin and remove all event listeners. */
|
|
47
66
|
public destroy(): void {
|
|
48
67
|
if (!this._flicking) return;
|
|
49
68
|
|
|
@@ -52,6 +71,7 @@ class Parallax implements Plugin {
|
|
|
52
71
|
this._flicking = null;
|
|
53
72
|
}
|
|
54
73
|
|
|
74
|
+
/** Recalculate and apply the parallax effect to all visible panels. */
|
|
55
75
|
public update = (): void => {
|
|
56
76
|
this._onMove();
|
|
57
77
|
};
|
|
@@ -66,11 +86,11 @@ class Parallax implements Plugin {
|
|
|
66
86
|
panels.forEach(panel => {
|
|
67
87
|
const progress = panel.outsetProgress;
|
|
68
88
|
const el = panel.element;
|
|
69
|
-
const target = this._selector ? el.querySelector
|
|
89
|
+
const target = this._selector ? (el.querySelector(this._selector) as HTMLElement) : el;
|
|
70
90
|
const parentTarget = target.parentNode as Element;
|
|
71
91
|
const rect = target.getBoundingClientRect();
|
|
72
92
|
const parentRect = parentTarget.getBoundingClientRect();
|
|
73
|
-
const position = (parentRect.width - rect.width) / 2 * progress * this._scale;
|
|
93
|
+
const position = ((parentRect.width - rect.width) / 2) * progress * this._scale;
|
|
74
94
|
const transform = `translate(-50%) translate(${position}px)`;
|
|
75
95
|
const style = target.style;
|
|
76
96
|
|
package/src/Perspective.ts
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
import Flicking, { EVENTS, Plugin } from "@egjs/flicking";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Options for the {@link Perspective} plugin
|
|
6
|
+
*/
|
|
7
|
+
export interface PerspectiveOptions {
|
|
8
|
+
/**
|
|
9
|
+
* CSS selector for the element to apply the perspective effect. If empty, the panel element itself is used
|
|
10
|
+
* @defaultValue ""
|
|
11
|
+
*/
|
|
5
12
|
selector: string;
|
|
13
|
+
/**
|
|
14
|
+
* Effect amplification scale
|
|
15
|
+
* @defaultValue 1
|
|
16
|
+
*/
|
|
6
17
|
scale: number;
|
|
18
|
+
/**
|
|
19
|
+
* Rotation amplification scale
|
|
20
|
+
* @defaultValue 1
|
|
21
|
+
*/
|
|
7
22
|
rotate: number;
|
|
23
|
+
/**
|
|
24
|
+
* The value of the CSS `perspective` property (px)
|
|
25
|
+
* @defaultValue 1000
|
|
26
|
+
*/
|
|
8
27
|
perspective: number;
|
|
9
28
|
}
|
|
10
29
|
|
|
11
30
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @memberof Flicking.Plugins
|
|
31
|
+
* A plugin to apply 3D perspective effect while panels are moving
|
|
32
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/perspective | Demo: Perspective}
|
|
15
33
|
*/
|
|
16
34
|
class Perspective implements Plugin {
|
|
17
35
|
private _flicking: Flicking | null;
|
|
@@ -22,27 +40,50 @@ class Perspective implements Plugin {
|
|
|
22
40
|
private _rotate: PerspectiveOptions["rotate"];
|
|
23
41
|
private _perspective: PerspectiveOptions["perspective"];
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
public get
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
/** Current value of the {@link PerspectiveOptions.selector | selector} option. */
|
|
44
|
+
public get selector() {
|
|
45
|
+
return this._selector;
|
|
46
|
+
}
|
|
47
|
+
/** Current value of the {@link PerspectiveOptions.scale | scale} option. */
|
|
48
|
+
public get scale() {
|
|
49
|
+
return this._scale;
|
|
50
|
+
}
|
|
51
|
+
/** Current value of the {@link PerspectiveOptions.rotate | rotate} option. */
|
|
52
|
+
public get rotate() {
|
|
53
|
+
return this._rotate;
|
|
54
|
+
}
|
|
55
|
+
/** Current value of the {@link PerspectiveOptions.perspective | perspective} option. */
|
|
56
|
+
public get perspective() {
|
|
57
|
+
return this._perspective;
|
|
58
|
+
}
|
|
29
59
|
|
|
30
|
-
|
|
31
|
-
public set
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
/** Sets {@link PerspectiveOptions.selector | selector}. */
|
|
61
|
+
public set selector(val: string) {
|
|
62
|
+
this._selector = val;
|
|
63
|
+
}
|
|
64
|
+
/** Sets {@link PerspectiveOptions.scale | scale}. */
|
|
65
|
+
public set scale(val: number) {
|
|
66
|
+
this._scale = val;
|
|
67
|
+
}
|
|
68
|
+
/** Sets {@link PerspectiveOptions.rotate | rotate}. */
|
|
69
|
+
public set rotate(val: number) {
|
|
70
|
+
this._rotate = val;
|
|
71
|
+
}
|
|
72
|
+
/** Sets {@link PerspectiveOptions.perspective | perspective}. */
|
|
73
|
+
public set perspective(val: number) {
|
|
74
|
+
this._perspective = val;
|
|
75
|
+
}
|
|
34
76
|
|
|
35
77
|
/**
|
|
36
|
-
* @param -
|
|
37
|
-
* @param - Effect amplication scale.<ko>효과 증폭도</ko>
|
|
38
|
-
* @param - Effect amplication rotate.<ko>회전 증폭도</ko>
|
|
39
|
-
* @param - The value of perspective CSS property. <ko>css perspective 속성 값</ko>
|
|
78
|
+
* @param options - Options for the Perspective instance
|
|
40
79
|
* @example
|
|
41
80
|
* ```ts
|
|
42
|
-
* flicking.addPlugins(new Perspective({ selector: "p", scale: 1, rotate: 1, perspective
|
|
81
|
+
* flicking.addPlugins(new Perspective({ selector: "p", scale: 1, rotate: 1, perspective: 1000 }));
|
|
43
82
|
* ```
|
|
44
83
|
*/
|
|
45
|
-
public constructor(
|
|
84
|
+
public constructor(options: Partial<PerspectiveOptions> = {}) {
|
|
85
|
+
const { selector = "", scale = 1, rotate = 1, perspective = 1000 } = options;
|
|
86
|
+
|
|
46
87
|
this._flicking = null;
|
|
47
88
|
this._selector = selector;
|
|
48
89
|
this._scale = scale;
|
|
@@ -50,6 +91,9 @@ class Perspective implements Plugin {
|
|
|
50
91
|
this._perspective = perspective;
|
|
51
92
|
}
|
|
52
93
|
|
|
94
|
+
/** Initialize the plugin and apply the perspective effect to the Flicking instance.
|
|
95
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
96
|
+
*/
|
|
53
97
|
public init(flicking: Flicking): void {
|
|
54
98
|
if (this._flicking) {
|
|
55
99
|
this.destroy();
|
|
@@ -62,6 +106,7 @@ class Perspective implements Plugin {
|
|
|
62
106
|
this._onMove();
|
|
63
107
|
}
|
|
64
108
|
|
|
109
|
+
/** Destroy the plugin and remove all event listeners. */
|
|
65
110
|
public destroy(): void {
|
|
66
111
|
if (!this._flicking) return;
|
|
67
112
|
|
|
@@ -70,6 +115,7 @@ class Perspective implements Plugin {
|
|
|
70
115
|
this._flicking = null;
|
|
71
116
|
}
|
|
72
117
|
|
|
118
|
+
/** Recalculate and apply the perspective effect to all visible panels. */
|
|
73
119
|
public update = (): void => {
|
|
74
120
|
this._onMove();
|
|
75
121
|
};
|
|
@@ -78,7 +124,7 @@ class Perspective implements Plugin {
|
|
|
78
124
|
const flicking = this._flicking;
|
|
79
125
|
const selector = this._selector;
|
|
80
126
|
const scale = this._scale;
|
|
81
|
-
const rotate =
|
|
127
|
+
const rotate = this._rotate;
|
|
82
128
|
const perspective = this._perspective;
|
|
83
129
|
|
|
84
130
|
if (!flicking) return;
|
|
@@ -86,12 +132,13 @@ class Perspective implements Plugin {
|
|
|
86
132
|
const horizontal = flicking.horizontal;
|
|
87
133
|
const panels = flicking.visiblePanels;
|
|
88
134
|
|
|
89
|
-
panels.forEach(
|
|
135
|
+
panels.forEach(panel => {
|
|
90
136
|
const progress = panel.outsetProgress;
|
|
91
137
|
const el = panel.element;
|
|
92
|
-
const target = selector ? el.querySelector
|
|
138
|
+
const target = selector ? (el.querySelector(selector) as HTMLElement) : el;
|
|
93
139
|
const panelScale = 1 / (Math.abs(progress * scale) + 1);
|
|
94
|
-
const rotateDegree =
|
|
140
|
+
const rotateDegree =
|
|
141
|
+
progress > 0 ? Math.min(90, progress * 100 * rotate) : Math.max(-90, progress * 100 * rotate);
|
|
95
142
|
const [rotateX, rotateY] = horizontal ? [0, rotateDegree] : [rotateDegree, 0];
|
|
96
143
|
|
|
97
144
|
target.style.transform = `perspective(${perspective}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(${panelScale})`;
|