|
98 | 98 | return extended; |
99 | 99 | }; |
100 | 100 |
|
| 101 | + |
| 102 | + |
101 | 103 | /** |
102 | 104 | * Get movable element container |
103 | 105 | * @private |
|
113 | 115 | return _container; |
114 | 116 | }; |
115 | 117 |
|
| 118 | + |
| 119 | + |
116 | 120 | /** |
117 | 121 | * Calculate page percent scrolled. |
118 | 122 | * @private |
|
124 | 128 | return _scrollOffset / ( _height - documentElement.clientHeight ); |
125 | 129 | }; |
126 | 130 |
|
| 131 | + |
| 132 | + |
127 | 133 | /** |
128 | 134 | * Calculate variables used to determine elements position |
129 | 135 | * @private |
|
152 | 158 | } |
153 | 159 | }; |
154 | 160 |
|
| 161 | + |
| 162 | + |
| 163 | + /** |
| 164 | + * Get position data object for the element. |
| 165 | + * @returns {Object} Position data object for element or false if not found. |
| 166 | + */ |
| 167 | + var getPositionDataByElement = function ( el ) { |
| 168 | + for (var i = 0; i < _positions.length; i++) { |
| 169 | + if ( _positions[i].element == el ) { |
| 170 | + return _positions[i]; |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + // Return false if not found |
| 175 | + return false; |
| 176 | + } |
| 177 | + |
| 178 | + |
| 179 | + |
155 | 180 | /** |
156 | 181 | * Initializes positions for each moving element. |
157 | 182 | * @private |
|
182 | 207 | } |
183 | 208 |
|
184 | 209 | var elementPosition = { |
| 210 | + element: _movingElements[i], |
185 | 211 | container: getElementContainer( _movingElements[i] ), |
186 | 212 | baseSizeOn: baseSizeOn, |
187 | 213 | start: { |
|
309 | 335 | }; |
310 | 336 |
|
311 | 337 | /** |
312 | | - * Exposes scroll percentage |
| 338 | + * Get scroll percentage for the element or page. |
| 339 | + * @param {string} el Target element css selector. |
| 340 | + * @return {float} Scroll percentage for the element or the page. |
313 | 341 | */ |
314 | | - publicMethods.getScrollPercent = function () { |
315 | | - return calculatePageScrollPercent(); |
| 342 | + publicMethods.getScrollPercent = function ( selector ) { |
| 343 | + // Calculate page scroll if no selector was passed |
| 344 | + if ( selector == undefined ) { |
| 345 | + return calculatePageScrollPercent(); |
| 346 | + } |
| 347 | + |
| 348 | + // Find element |
| 349 | + // Return false if not found |
| 350 | + var el = document.querySelector( selector ); |
| 351 | + if ( el == null ) return false; |
| 352 | + |
| 353 | + // Calculate element scroll percent |
| 354 | + var positionData = getPositionDataByElement( el ); |
| 355 | + if ( positionData ) { |
| 356 | + calculatePercent( positionData ); |
| 357 | + return _scrollPercent; |
| 358 | + } |
| 359 | + |
| 360 | + // Return false otherwise |
| 361 | + return false; |
316 | 362 | }; |
317 | 363 |
|
318 | 364 |
|
|
0 commit comments