-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Carousel v2: add logic for spacers for looping. (#20293)
This implements the logic needed to ensure the correct amount of space is reserved for either side of the carousel when looping. The logic to snap slides as well as to actually move them still needs to be added.
- Loading branch information
Sepand Parhami
authored
Jan 16, 2019
1 parent
2fc85a2
commit d135c75
Showing
3 changed files
with
465 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2019 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {mod} from '../../../src/utils/math'; | ||
|
||
/** | ||
* Calculates the distance between two indicies in an Array, treating the first | ||
* and last indicies as adjacent. In the array ['a', 'b', 'c'], the | ||
* wrappingDistance between 'a' and 'c' is 1. Likewise, the wrappingDistance | ||
* betweeb 'a' and 'b' is also 1. | ||
* @param {number} a A start index. | ||
* @param {number} b An end index. | ||
* @param {!IArrayLike} arr An array like Object. | ||
*/ | ||
export function wrappingDistance(a, b, arr) { | ||
return a === b ? 0 : Math.min( | ||
forwardWrappingDistance(a, b, arr), | ||
backwardWrappingDistance(a, b, arr)); | ||
} | ||
|
||
/** | ||
* Calculates the forwards distance between two indicies in an Array, treating | ||
* the first and last indicies as adjacent. In the array ['a', 'b', 'c'], the | ||
* forwardWrappingDistance between 'b' and 'a' is 2. | ||
* @param {number} a A start index. | ||
* @param {number} b An end index. | ||
* @param {!IArrayLike} arr An array like Object. | ||
*/ | ||
export function forwardWrappingDistance(a, b, {length}) { | ||
return a === b ? length : mod(b - a, length); | ||
} | ||
|
||
/** | ||
* Calculates the backwards distance between two indicies in an Array, treating | ||
* the first and last indicies as adjacent. In the array ['a', 'b', 'c'], the | ||
* backwardWrappingDistance between 'a' and 'b' is 2. | ||
* @param {number} a A start index. | ||
* @param {number} b An end index. | ||
* @param {!IArrayLike} arr An array like Object. | ||
*/ | ||
export function backwardWrappingDistance(a, b, {length}) { | ||
return a === b ? length : mod(a - b, length); | ||
} |
Oops, something went wrong.