Skip to content

Instantly share code, notes, and snippets.

View sereezha's full-sized avatar
🇺🇦

Serhii Hovorovskyi sereezha

🇺🇦
View GitHub Profile
.sr-only {
border: 0 !important;
clip: rect(1px, 1px, 1px, 1px) !important;
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
const capitalize = ([first, ...rest], lowerRest = false) =>
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');
export default (el) => {
const $el = $(el);
const top = $el.offset().top - 250;
const bottom = top + $el.height();
const scroll = $(window).scrollTop();
return scroll > top && scroll < bottom;
}
function random(min, max) {
return Math.random() * (max - min) + min;
}
function isAnyPartOfElementInViewport(el) {
const rect = el.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
const windowHeight = (window.innerHeight || document.documentElement.clientHeight);
const windowWidth = (window.innerWidth || document.documentElement.clientWidth);
// http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0);
const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0);
isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function checkVisibility(el) {
var dTop = $(window).scrollTop(),
dBot = dTop + $(window).height(),
elTop = el.offset().top,
elBot = elTop + el.height();
return ((elTop <= dBot) && (elBot >= dTop));
}