Last active
November 18, 2024 11:34
-
-
Save maximilliangeorge/af1a2cc379efd6fea8277f15e2687092 to your computer and use it in GitHub Desktop.
Pure function carousel wrap
This file contains hidden or 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
// Creates a helper function to create looping carousel slides. | |
// @param {number} arrIndex - Index of slide in array (starting from 0) | |
// @param {number} arrLength - The number of slides in the carousel | |
// @returns {function} offset - The helper function. | |
export const steps = (arrIndex, arrLength) => (progress) => { | |
const wraps = ((arrIndex + 1) - progress) / arrLength | |
const flooredWraps = Math.floor(wraps) | |
return 0 - flooredWraps | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment