@egjs/flicking 4.13.2-beta.1 → 4.14.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/core-packages-link.js +53 -16
- package/debug/reactive/index.html +240 -0
- package/declaration/index.d.ts +1 -0
- package/declaration/reactive/index.d.ts +25 -0
- package/dist/flicking.cjs.js +202 -10
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +196 -8
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +206 -12
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.js +2 -2
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +527 -8
- package/dist/flicking.pkgd.js.map +1 -1
- package/dist/flicking.pkgd.min.js +2 -2
- package/dist/flicking.pkgd.min.js.map +1 -1
- package/package.json +3 -2
- package/src/control/Control.ts +3 -1
- package/src/index.ts +1 -0
- package/src/index.umd.ts +2 -0
- package/src/reactive/index.ts +326 -0
- package/debug/example/index.html +0 -82
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.1-beta.0",
|
|
4
4
|
"description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
|
|
5
5
|
"main": "dist/flicking.cjs.js",
|
|
6
6
|
"module": "dist/flicking.esm.js",
|
|
@@ -139,7 +139,8 @@
|
|
|
139
139
|
"typescript-transform-paths": "^2.2.3"
|
|
140
140
|
},
|
|
141
141
|
"dependencies": {
|
|
142
|
-
"@
|
|
142
|
+
"@cfcs/core": "^0.1.0",
|
|
143
|
+
"@egjs/axes": "^3.9.1",
|
|
143
144
|
"@egjs/component": "^3.0.1",
|
|
144
145
|
"@egjs/imready": "^1.3.1",
|
|
145
146
|
"@egjs/list-differ": "^1.0.1"
|
package/src/control/Control.ts
CHANGED
|
@@ -389,7 +389,9 @@ abstract class Control {
|
|
|
389
389
|
return animate();
|
|
390
390
|
} else {
|
|
391
391
|
return animate().then(async () => {
|
|
392
|
-
|
|
392
|
+
if (flicking.initialized) {
|
|
393
|
+
await flicking.renderer.render();
|
|
394
|
+
}
|
|
393
395
|
}).catch(err => {
|
|
394
396
|
if (axesEvent && err instanceof FlickingError && err.code === ERROR.CODE.ANIMATION_INTERRUPTED) return;
|
|
395
397
|
throw err;
|
package/src/index.ts
CHANGED
package/src/index.umd.ts
CHANGED
|
@@ -10,6 +10,7 @@ import * as Control from "./control";
|
|
|
10
10
|
import * as Renderer from "./renderer";
|
|
11
11
|
import * as Constants from "./const/external";
|
|
12
12
|
import * as CFC from "./cfc";
|
|
13
|
+
import * as FlickingReactiveAPI from "./reactive";
|
|
13
14
|
import * as Utils from "./utils";
|
|
14
15
|
import { merge } from "./utils";
|
|
15
16
|
|
|
@@ -21,5 +22,6 @@ merge(Flicking, Constants);
|
|
|
21
22
|
merge(Flicking, CFC);
|
|
22
23
|
merge(Flicking, Utils);
|
|
23
24
|
merge(Flicking, CrossFlicking);
|
|
25
|
+
merge(Flicking, FlickingReactiveAPI);
|
|
24
26
|
|
|
25
27
|
export default Flicking;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adaptReactive,
|
|
3
|
+
reactive,
|
|
4
|
+
ReactiveObject,
|
|
5
|
+
ReactiveSetupAdapter
|
|
6
|
+
} from "@cfcs/core";
|
|
7
|
+
|
|
8
|
+
import Flicking from "../Flicking";
|
|
9
|
+
|
|
10
|
+
// Check if Flicking has reached the first panel
|
|
11
|
+
const getIsReachStart = (flicking: Flicking) => !flicking.circular && flicking.index === 0;
|
|
12
|
+
|
|
13
|
+
// Check if Flicking has reached the last panel
|
|
14
|
+
const getIsReachEnd = (flicking: Flicking) => !flicking.circular && flicking.index === flicking.panelCount - 1;
|
|
15
|
+
|
|
16
|
+
// Get the total number of panels
|
|
17
|
+
const getTotalPanelCount = (flicking: Flicking) => flicking.panelCount;
|
|
18
|
+
|
|
19
|
+
// Get the current active panel index
|
|
20
|
+
const getCurrentPanelIndex = (flicking: Flicking) => flicking.index;
|
|
21
|
+
|
|
22
|
+
// Calculate the overall scroll progress percentage based on the current camera position
|
|
23
|
+
const getProgress = (flicking: Flicking) => {
|
|
24
|
+
const cam = flicking.camera;
|
|
25
|
+
|
|
26
|
+
const progressRatio = (cam.position - cam.range.min) / (cam.range.max - cam.range.min);
|
|
27
|
+
|
|
28
|
+
const percent = Math.min(Math.max(progressRatio, 0), 1) * 100;
|
|
29
|
+
|
|
30
|
+
return percent;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Calculate the progress between panels including decimal values
|
|
34
|
+
const getIndexProgress = (flicking: Flicking) => {
|
|
35
|
+
const cam = flicking.camera;
|
|
36
|
+
const anchorPoints = cam.anchorPoints;
|
|
37
|
+
const length = anchorPoints.length;
|
|
38
|
+
const cameraPosition = cam.position;
|
|
39
|
+
const isCircular = flicking.circularEnabled;
|
|
40
|
+
let indexProgress = 0;
|
|
41
|
+
|
|
42
|
+
const { min, max } = cam.range;
|
|
43
|
+
const firstAnchorPoint = anchorPoints[0];
|
|
44
|
+
const lastAnchorPoint = anchorPoints[length - 1];
|
|
45
|
+
const distanceLastToFirst = (max - lastAnchorPoint.position) + (firstAnchorPoint.position - min);
|
|
46
|
+
|
|
47
|
+
anchorPoints.some((anchorPoint, index) => {
|
|
48
|
+
const anchorPosition = anchorPoint.position;
|
|
49
|
+
const nextAnchorPoint = anchorPoints[index + 1];
|
|
50
|
+
|
|
51
|
+
if (index === 0 && cameraPosition <= anchorPosition) {
|
|
52
|
+
if (isCircular) {
|
|
53
|
+
indexProgress = (cameraPosition - anchorPosition) / distanceLastToFirst;
|
|
54
|
+
} else {
|
|
55
|
+
indexProgress = (cameraPosition - anchorPosition) / anchorPoint.panel.size;
|
|
56
|
+
}
|
|
57
|
+
} else if (index === length - 1 && cameraPosition >= anchorPosition) {
|
|
58
|
+
if (isCircular) {
|
|
59
|
+
indexProgress = index + (cameraPosition - anchorPosition) / distanceLastToFirst;
|
|
60
|
+
} else {
|
|
61
|
+
indexProgress = index + (cameraPosition - anchorPosition) / anchorPoint.panel.size;
|
|
62
|
+
}
|
|
63
|
+
} else if (nextAnchorPoint && anchorPosition <= cameraPosition && cameraPosition <= nextAnchorPoint.position) {
|
|
64
|
+
indexProgress = index + (cameraPosition - anchorPosition) / (nextAnchorPoint.position - anchorPosition);
|
|
65
|
+
} else {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return indexProgress;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Reactive object type that combines state and methods for Flicking
|
|
76
|
+
* This type provides reactive state properties and methods that automatically update
|
|
77
|
+
* when the Flicking instance state changes.
|
|
78
|
+
* @ko Flicking의 상태와 메서드를 결합한 반응형 객체 타입
|
|
79
|
+
* 이 타입은 Flicking 인스턴스의 상태가 변경될 때 자동으로 업데이트되는
|
|
80
|
+
* 반응형 상태 속성들과 메서드들을 제공합니다.
|
|
81
|
+
* @typedef
|
|
82
|
+
* @see {@link https://naver.github.io/egjs-flicking/Demos#reactive-api-demo}
|
|
83
|
+
* @example
|
|
84
|
+
* ```jsx
|
|
85
|
+
* const flickingRef = React.useRef(null);
|
|
86
|
+
* const {
|
|
87
|
+
* progress
|
|
88
|
+
* } = useFlickingReactiveAPI(flickingRef);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export type FlickingReactiveObject = ReactiveObject<FlickingReactiveState & FlickingReactiveMethod>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Reactive state properties for Flicking
|
|
95
|
+
* @ko Flicking의 반응형 상태 속성들
|
|
96
|
+
* @typedef
|
|
97
|
+
*/
|
|
98
|
+
export interface FlickingReactiveState {
|
|
99
|
+
/**
|
|
100
|
+
* Whether Flicking has reached the first panel<ko>첫 번째 패널에 도달했는지 여부</ko>
|
|
101
|
+
*/
|
|
102
|
+
isReachStart: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether Flicking has reached the last panel<ko>마지막 패널에 도달했는지 여부</ko>
|
|
105
|
+
*/
|
|
106
|
+
isReachEnd: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Total number of panels<ko>전체 패널 개수</ko>
|
|
109
|
+
*/
|
|
110
|
+
totalPanelCount: number;
|
|
111
|
+
/**
|
|
112
|
+
* Current active panel index<ko>현재 활성화된 패널의 인덱스</ko>
|
|
113
|
+
*/
|
|
114
|
+
currentPanelIndex: number;
|
|
115
|
+
/**
|
|
116
|
+
* Overall scroll progress percentage (0-100)<ko>전체 스크롤 진행률 (0-100)</ko>
|
|
117
|
+
*/
|
|
118
|
+
progress: number;
|
|
119
|
+
/**
|
|
120
|
+
* Panel progress with decimal values<ko>소수점을 포함한 패널 진행률</ko>
|
|
121
|
+
*/
|
|
122
|
+
indexProgress: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Reactive methods for Flicking
|
|
127
|
+
* @ko Flicking의 반응형 메서드들
|
|
128
|
+
* @typedef
|
|
129
|
+
*/
|
|
130
|
+
export interface FlickingReactiveMethod {
|
|
131
|
+
/**
|
|
132
|
+
* Move to a specific panel index<ko>특정 패널 인덱스로 이동</ko>
|
|
133
|
+
* @param i - Target panel index<ko>목표 패널 인덱스</ko>
|
|
134
|
+
* @returns Promise that resolves when movement is complete<ko>이동이 완료되면 resolve되는 Promise</ko>
|
|
135
|
+
*/
|
|
136
|
+
moveTo: (i: number) => Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Data required for reactive API setup
|
|
141
|
+
* @ko 반응형 API 설정에 필요한 데이터
|
|
142
|
+
* @typedef
|
|
143
|
+
*/
|
|
144
|
+
export interface FlickingReactiveData {
|
|
145
|
+
/**
|
|
146
|
+
* Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
|
|
147
|
+
*/
|
|
148
|
+
flicking?: Flicking;
|
|
149
|
+
/**
|
|
150
|
+
* Flicking options used for initialization<ko>초기화에 사용되는 Flicking 옵션</ko>
|
|
151
|
+
*/
|
|
152
|
+
options?: FlickingReactiveAPIOptions;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Options for Flicking reactive API that help optimize initial rendering in SSR scenarios
|
|
157
|
+
* These options allow you to set initial state values before the Flicking instance is fully initialized,
|
|
158
|
+
* preventing unnecessary re-renders when the actual Flicking state is applied.
|
|
159
|
+
* @ko SSR 상황 등에서 초기 렌더링을 최적화할 수 있게 하는 Flicking 반응형 API 옵션
|
|
160
|
+
* 이 옵션들을 통해 Flicking 인스턴스가 완전히 초기화되기 전에 초기 상태 값을 설정할 수 있어,
|
|
161
|
+
* 실제 Flicking 상태가 적용될 때 불필요한 리렌더링을 방지할 수 있습니다.
|
|
162
|
+
* @typedef
|
|
163
|
+
* @example
|
|
164
|
+
* ```js
|
|
165
|
+
* const options = {
|
|
166
|
+
* defaultIndex: 2,
|
|
167
|
+
* totalPanelCount: 5
|
|
168
|
+
* };
|
|
169
|
+
* const reactiveObj = connectFlickingReactiveAPI(flicking, options);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export interface FlickingReactiveAPIOptions {
|
|
173
|
+
/**
|
|
174
|
+
* Initial panel index to start with. This sets the currentPanelIndex and indexProgress initial values.
|
|
175
|
+
* Also affects isReachStart and isReachEnd initial value setting.
|
|
176
|
+
* @ko 시작할 초기 패널 인덱스. currentPanelIndex와 indexProgress의 초기값을 설정합니다.
|
|
177
|
+
* 또한 isReachStart, isReachEnd 초기값 계산에도 영향을 줍니다.
|
|
178
|
+
* @default 0
|
|
179
|
+
*/
|
|
180
|
+
defaultIndex?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Total number of panels in the Flicking instance. This sets the totalPanelCount initial value
|
|
183
|
+
* and helps prevent layout shifts during SSR hydration.
|
|
184
|
+
* @ko Flicking 인스턴스의 전체 패널 개수. totalPanelCount의 초기값을 설정하며
|
|
185
|
+
* SSR 하이드레이션 과정에서 레이아웃 시프트를 방지하는 데 도움이 됩니다.
|
|
186
|
+
* @default 0
|
|
187
|
+
*/
|
|
188
|
+
totalPanelCount?: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Internal reactive API adapter for Flicking that manages state and event listeners
|
|
194
|
+
* This adapter is used internally by framework-specific packages (react-flicking, vue-flicking, etc.)
|
|
195
|
+
* to provide reactive API support. Users rarely need to use this directly.
|
|
196
|
+
* @ko Flicking의 상태와 이벤트 리스너를 관리하는 내부 반응형 API 어댑터
|
|
197
|
+
* 이 어댑터는 react-flicking, vue-flicking 등의 프레임워크별 패키지에서 내부적으로 사용되어
|
|
198
|
+
* 반응형 API 지원을 제공합니다. 사용자가 직접 사용할 일은 거의 없습니다.
|
|
199
|
+
* @param onInit - Callback when reactive object is initialized<ko>반응형 객체가 초기화될 때 호출되는 콜백</ko>
|
|
200
|
+
* @param onDestroy - Callback when reactive object is destroyed<ko>반응형 객체가 파괴될 때 호출되는 콜백</ko>
|
|
201
|
+
* @param setMethods - Function to set available methods<ko>사용 가능한 메서드를 설정하는 함수</ko>
|
|
202
|
+
* @returns Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
|
|
203
|
+
*/
|
|
204
|
+
const flickingReactiveAPIAdapter: ReactiveSetupAdapter<
|
|
205
|
+
FlickingReactiveObject,
|
|
206
|
+
FlickingReactiveState,
|
|
207
|
+
"moveTo",
|
|
208
|
+
FlickingReactiveData
|
|
209
|
+
> = ({ onInit, onDestroy, setMethods, getProps }) => {
|
|
210
|
+
let flicking: Flicking | undefined;
|
|
211
|
+
|
|
212
|
+
// Move to a specific panel index
|
|
213
|
+
const moveTo = (i: number) => {
|
|
214
|
+
if (flicking == null) {
|
|
215
|
+
return Promise.reject(new Error("Flicking instance is not available"));
|
|
216
|
+
}
|
|
217
|
+
if (flicking?.animating) {
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
}
|
|
220
|
+
return flicking.moveTo(i);
|
|
221
|
+
};
|
|
222
|
+
setMethods(["moveTo"]);
|
|
223
|
+
|
|
224
|
+
const options = getProps().options;
|
|
225
|
+
|
|
226
|
+
// options를 고려하지 않고 초기값을 설정해도 동작에는 아무런 문제가 없으나, 이 시점의 초기값과 컴포넌트 init 단계에서의 초기값이 다르면 화면 리렌더링이 발생할 수 있으므로
|
|
227
|
+
// 이렇게 미리 옵션을 통해서 예측할 수 있는 부분들은 맞춰둔다.
|
|
228
|
+
const reactiveObj: FlickingReactiveObject = reactive({
|
|
229
|
+
isReachStart: options?.defaultIndex ? options?.defaultIndex === 0 : true,
|
|
230
|
+
isReachEnd: (options?.totalPanelCount && options?.defaultIndex) ? (options.defaultIndex === options.totalPanelCount - 1) : false,
|
|
231
|
+
totalPanelCount: options?.totalPanelCount ?? 0,
|
|
232
|
+
currentPanelIndex: options?.defaultIndex ?? 0,
|
|
233
|
+
progress: 0,
|
|
234
|
+
indexProgress: options?.defaultIndex ?? 0,
|
|
235
|
+
moveTo
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Update state when panel changes
|
|
239
|
+
const onChanged = () => {
|
|
240
|
+
if (flicking === undefined) return;
|
|
241
|
+
|
|
242
|
+
reactiveObj.isReachStart = getIsReachStart(flicking);
|
|
243
|
+
reactiveObj.isReachEnd = getIsReachEnd(flicking);
|
|
244
|
+
reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// Update state when panel count changes
|
|
248
|
+
const onPanelChange = () => {
|
|
249
|
+
if (flicking === undefined) return;
|
|
250
|
+
|
|
251
|
+
onChanged();
|
|
252
|
+
reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// Update progress when camera moves
|
|
256
|
+
const onMove = () => {
|
|
257
|
+
if (flicking === undefined) return;
|
|
258
|
+
|
|
259
|
+
reactiveObj.progress = getProgress(flicking);
|
|
260
|
+
reactiveObj.indexProgress = getIndexProgress(flicking);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
onInit((inst, data) => {
|
|
264
|
+
flicking = data.flicking;
|
|
265
|
+
if (flicking === undefined) return;
|
|
266
|
+
|
|
267
|
+
reactiveObj.isReachStart = getIsReachStart(flicking);
|
|
268
|
+
reactiveObj.isReachEnd = getIsReachEnd(flicking);
|
|
269
|
+
reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
|
|
270
|
+
reactiveObj.progress = getProgress(flicking);
|
|
271
|
+
|
|
272
|
+
reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
|
|
273
|
+
|
|
274
|
+
flicking?.on("changed", onChanged);
|
|
275
|
+
flicking?.on("panelChange", onPanelChange);
|
|
276
|
+
flicking?.on("move", onMove);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
onDestroy(() => {
|
|
280
|
+
flicking?.off("changed", onChanged);
|
|
281
|
+
flicking?.off("panelChange", onPanelChange);
|
|
282
|
+
flicking?.off("move", onMove);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return reactiveObj;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Connect Flicking instance to reactive API
|
|
290
|
+
* @ko Flicking 인스턴스를 반응형 API에 연결합니다
|
|
291
|
+
* @param {Flicking} flicking - Flicking instance to connect<ko>연결할 Flicking 인스턴스</ko>
|
|
292
|
+
* @param {FlickingReactiveAPIOptions} [options] - Flicking options<ko>Flicking 옵션</ko>
|
|
293
|
+
* @returns {FlickingReactiveObject} Reactive object with Flicking state and methods<ko>Flicking 상태와 메서드를 포함한 반응형 객체</ko>
|
|
294
|
+
* @example
|
|
295
|
+
* ```js
|
|
296
|
+
* import Flicking, { connectFlickingReactiveAPI } from "@egjs/flicking";
|
|
297
|
+
*
|
|
298
|
+
* const flicking = new Flicking("#el");
|
|
299
|
+
* const reactiveObj = connectFlickingReactiveAPI(flicking);
|
|
300
|
+
*
|
|
301
|
+
* // Access reactive state
|
|
302
|
+
* console.log("Current panel:", reactiveObj.currentPanelIndex);
|
|
303
|
+
* console.log("Progress:", reactiveObj.progress + "%");
|
|
304
|
+
* console.log("Is at start:", reactiveObj.isReachStart);
|
|
305
|
+
* console.log("Is at end:", reactiveObj.isReachEnd);
|
|
306
|
+
* console.log("Total panels:", reactiveObj.totalPanelCount);
|
|
307
|
+
* console.log("Index progress:", reactiveObj.indexProgress);
|
|
308
|
+
*
|
|
309
|
+
* // Subscribe to state changes
|
|
310
|
+
* reactiveObj.subscribe("currentPanelIndex", (nextValue) => {
|
|
311
|
+
* console.log("Panel changed to:", nextValue);
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* // Use reactive methods
|
|
315
|
+
* reactiveObj.moveTo(2); // Move to third panel
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
const connectFlickingReactiveAPI = (flicking: Flicking, options?: FlickingReactiveAPIOptions) => {
|
|
319
|
+
const obj = adaptReactive(flickingReactiveAPIAdapter, () => ({ flicking, options }));
|
|
320
|
+
obj.mounted();
|
|
321
|
+
const instance = obj.instance();
|
|
322
|
+
obj.init();
|
|
323
|
+
return instance;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export { flickingReactiveAPIAdapter, connectFlickingReactiveAPI };
|
package/debug/example/index.html
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Flicking Basic Demo</title>
|
|
7
|
-
<link rel="stylesheet" href="../../dist/flicking.css" />
|
|
8
|
-
<style>
|
|
9
|
-
.flicking-viewport {
|
|
10
|
-
width: 500px;
|
|
11
|
-
height: 300px;
|
|
12
|
-
margin: 0 auto;
|
|
13
|
-
}
|
|
14
|
-
.panel {
|
|
15
|
-
width: 200px;
|
|
16
|
-
height: 300px;
|
|
17
|
-
margin-right: 10px;
|
|
18
|
-
display: flex;
|
|
19
|
-
align-items: center;
|
|
20
|
-
justify-content: center;
|
|
21
|
-
font-size: 24px;
|
|
22
|
-
color: white;
|
|
23
|
-
}
|
|
24
|
-
.navigation {
|
|
25
|
-
text-align: center;
|
|
26
|
-
margin-top: 20px;
|
|
27
|
-
}
|
|
28
|
-
.navigation button {
|
|
29
|
-
margin: 0 5px;
|
|
30
|
-
padding: 5px 10px;
|
|
31
|
-
}
|
|
32
|
-
</style>
|
|
33
|
-
</head>
|
|
34
|
-
<body>
|
|
35
|
-
<div class="flicking-viewport">
|
|
36
|
-
<div class="flicking-camera">
|
|
37
|
-
<div class="panel" style="background-color: #f44336">Panel 1</div>
|
|
38
|
-
<div class="panel" style="background-color: #2196f3">Panel 2</div>
|
|
39
|
-
<div class="panel" style="background-color: #4caf50">Panel 3</div>
|
|
40
|
-
<div class="panel" style="background-color: #ffc107">Panel 4</div>
|
|
41
|
-
<div class="panel" style="background-color: #9c27b0">Panel 5</div>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
<div class="navigation">
|
|
45
|
-
<button id="prev">Previous</button>
|
|
46
|
-
<button id="next">Next</button>
|
|
47
|
-
</div>
|
|
48
|
-
|
|
49
|
-
<script src="../../dist/flicking.pkgd.js"></script>
|
|
50
|
-
<script>
|
|
51
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
52
|
-
const flicking = new Flicking(".flicking-viewport", {
|
|
53
|
-
circular: false,
|
|
54
|
-
moveType: "snap",
|
|
55
|
-
align: "center",
|
|
56
|
-
defaultIndex: 0,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Navigation buttons
|
|
60
|
-
const prevButton = document.getElementById("prev");
|
|
61
|
-
const nextButton = document.getElementById("next");
|
|
62
|
-
|
|
63
|
-
prevButton.addEventListener("click", () => {
|
|
64
|
-
flicking.prev();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
nextButton.addEventListener("click", () => {
|
|
68
|
-
flicking.next();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Update button states based on current index
|
|
72
|
-
flicking.on("moveEnd", () => {
|
|
73
|
-
prevButton.disabled = flicking.index === 0;
|
|
74
|
-
nextButton.disabled = flicking.index === flicking.panels.length - 1;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Initial button state
|
|
78
|
-
prevButton.disabled = true;
|
|
79
|
-
});
|
|
80
|
-
</script>
|
|
81
|
-
</body>
|
|
82
|
-
</html>
|