Last active
August 22, 2018 20:25
-
-
Save nikolaswise/9625987d0f79f4bf03caa0cdb1310449 to your computer and use it in GitHub Desktop.
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
| export const $ = (selector, context = document) => Array(...context.querySelectorAll(selector)) | |
| export const isEven = n => n === 0 || !!(n && !(n%2)); | |
| export const isInViewport = (el)=> { | |
| var rect = el.getBoundingClientRect(); | |
| return ( | |
| rect.top >= 0 && | |
| rect.left >= 0 && | |
| rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ | |
| rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ | |
| ); | |
| } | |
| export const closest = (className, context) => { | |
| var current; | |
| for (current = context; current; current = current.parentNode) { | |
| if (current.nodeType === 1 && current.classList.contains(className)) { | |
| break; | |
| } | |
| } | |
| return current; | |
| } | |
| export const getOffsetTop = (elem) => { | |
| let offsetTop = 0; | |
| do { | |
| if ( !isNaN( elem.offsetTop ) ){ | |
| offsetTop += elem.offsetTop; | |
| } | |
| } while( elem = elem.offsetParent ); | |
| return offsetTop; | |
| } | |
| export const boolify = string => string == 'true' | |
| export const delay = (ms) => new Promise((resolve, reject) => { | |
| setTimeout(() => resolve(), ms); | |
| }) | |
| // delay('2s').then(() => { | |
| // console.log('wow') | |
| // }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment