Created
April 8, 2016 19:40
-
-
Save goldhand/7c209c9200e8279937c10df9d2805abd to your computer and use it in GitHub Desktop.
returns a value from a set that meets conditions
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
function getActiveHeightTrigger(triggersMap) { | |
// returns the smalles height from a set of heights that is more than the window height | |
return triggersMap.reduce((pV, cV) => { | |
// is this height more than window? | |
let checkWindow = (cV.height >= window.innerHeight); | |
// is this height less than previous height? | |
let checkPrev = (cV.height < pV.height); | |
if (checkWindow) { | |
if (checkPrev || !pV.height) return cV; | |
} | |
return pV; | |
}, {}); | |
} | |
let tTest = [ | |
{ | |
height: 615, | |
className: 'height-615', | |
}, | |
{ | |
height: 675, | |
className: 'height-675', | |
}, | |
{ | |
height: 715, | |
className: 'height-715', | |
}, | |
{ | |
height: 815, | |
className: 'height-815', | |
}, | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment