Skip to content

Instantly share code, notes, and snippets.

@SrJSDev
SrJSDev / fade-in-out-effect.js
Last active November 10, 2022 21:03 — forked from crazy4groovy/lazyimg-IntersectionObserver.js
Intersection Observer examples
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer
const options = {};
const observer = new IntersectionObserver((entries, self) => {
entries.forEach(({isIntersecting, target}) => {
target.classList.toggle('show', isIntersecting);
})
}, options);
document.querySelectorAll('.hidden').forEach(target => observer.observe(target));
@SrJSDev
SrJSDev / throttle-func.js
Created November 15, 2022 06:33 — forked from crazy4groovy/throttle-func.js
A simple queue to throttle max X simultaneous async function executions (JavaScript)
export default function newQueue(
maxCurr = 10,
func,
{ logger, logtag = "" } = {}
) {
let curr = 0;
const queue = [];
async function scheduleWork() {
if (curr >= maxCurr || queue.length === 0) return;