|
72 | 72 | background-color: #4caf50; /* 채워지는 색 */ |
73 | 73 | transition: width 0.3s ease; /* 부드럽게 변화 */ |
74 | 74 | } |
| 75 | + #scroll-progress-bar { |
| 76 | + width: 600px; |
| 77 | + height: 20px; |
| 78 | + border-radius: 20px; |
| 79 | + background-color: #e0e0e0; |
| 80 | + overflow: hidden; |
| 81 | + } |
| 82 | + #scroll-progress-fill { |
| 83 | + height: 100%; |
| 84 | + width: 0%; /* 초기에는 0% 채워짐 */ |
| 85 | + background-color: #2196f3; /* 채워지는 색 */ |
| 86 | + transition: width 0.3s ease; /* 부드럽게 변화 */ |
| 87 | + } |
75 | 88 | </style> |
76 | 89 | </head> |
77 | 90 | <body> |
|
80 | 93 | <button class="navigation-btn" id="prev">Previous</button> |
81 | 94 | <div class="flicking-viewport"> |
82 | 95 | <div class="flicking-camera"> |
83 | | - <div class="flicking-panel">x0</div> |
| 96 | + <div class="flicking-panel" style="width: 500px;">x0</div> |
84 | 97 | <div class="flicking-panel">x1</div> |
85 | 98 | <div class="flicking-panel">x2</div> |
86 | 99 | <div class="flicking-panel">x3</div> |
|
93 | 106 | <div id="progress-bar"> |
94 | 107 | <div id="progress-fill"></div> |
95 | 108 | </div> |
| 109 | + <div id="scroll-progress-bar"> |
| 110 | + <div id="scroll-progress-fill"></div> |
| 111 | + </div> |
96 | 112 | </div> |
97 | 113 |
|
98 | 114 | <div class="add"> |
|
109 | 125 | <script src="../../dist/flicking.pkgd.js"></script> |
110 | 126 | <script> |
111 | 127 | document.addEventListener("DOMContentLoaded", () => { |
112 | | - const flicking = new Flicking(".flicking-viewport"); |
| 128 | + const flicking = new Flicking(".flicking-viewport", {renderOnlyVisible: true}); |
113 | 129 | const { connectFlickingStateApi } = Flicking; |
114 | 130 | const reactiveObj = connectFlickingStateApi(flicking); |
115 | | - const {isReachStart, isReachEnd, totalPanelCount, currentPanelIndex, moveTo} = reactiveObj |
| 131 | + const { |
| 132 | + isReachStart, |
| 133 | + isReachEnd, |
| 134 | + totalPanelCount, |
| 135 | + currentPanelIndex, |
| 136 | + moveTo, |
| 137 | + } = reactiveObj; |
116 | 138 |
|
117 | 139 | // Navigation buttons |
118 | 140 | const prevButton = document.getElementById("prev"); |
|
191 | 213 | const paginationElement = document.getElementById("pagination"); |
192 | 214 | const progressFillElement = document.getElementById("progress-fill"); |
193 | 215 |
|
194 | | - const pageNums = Array.from( |
195 | | - { length: totalPanelCount }, |
196 | | - (_, i) => { |
197 | | - const div = document.createElement("div"); |
198 | | - div.className = `pagination-num ${ |
199 | | - i === currentPanelIndex ? "active" : "" |
200 | | - }`; |
201 | | - div.textContent = `${i}`; |
202 | | - |
203 | | - div.addEventListener("click", (e) => { |
204 | | - moveTo(i); |
205 | | - }); |
206 | | - return div; |
207 | | - } |
208 | | - ); |
| 216 | + const pageNums = Array.from({ length: totalPanelCount }, (_, i) => { |
| 217 | + const div = document.createElement("div"); |
| 218 | + div.className = `pagination-num ${ |
| 219 | + i === currentPanelIndex ? "active" : "" |
| 220 | + }`; |
| 221 | + div.textContent = `${i}`; |
| 222 | + |
| 223 | + div.addEventListener("click", (e) => { |
| 224 | + moveTo(i); |
| 225 | + }); |
| 226 | + return div; |
| 227 | + }); |
209 | 228 |
|
210 | 229 | paginationElement.append(...pageNums); |
211 | 230 |
|
|
218 | 237 | }); |
219 | 238 | }); |
220 | 239 |
|
221 | | - reactiveObj.subscribe("progress", (nextValue) => { |
| 240 | + reactiveObj.subscribe("indexProgress", (nextValue) => { |
222 | 241 | progressFillElement.style.width = `${nextValue}%`; |
223 | | - }) |
224 | | - |
| 242 | + }); |
| 243 | + |
| 244 | + |
| 245 | + const scrollProgressFillElement = document.getElementById("scroll-progress-fill"); |
| 246 | + reactiveObj.subscribe("scrollProgress", (nextValue) => { |
| 247 | + scrollProgressFillElement.style.width = `${nextValue}%`; |
| 248 | + }); |
225 | 249 | }); |
226 | 250 | </script> |
227 | 251 | </body> |
|
0 commit comments