') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - aumiqx/scroll: Programmable scroll physics engine. Per-section friction, magnetic snap, configurable mass. ~4KB, zero dependencies. · GitHub
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

@aumiqx/scroll

Programmable scroll physics engine for the web. Per-section friction, magnetic snap points, configurable mass and inertia.

~4KB | TypeScript | Zero dependencies | Pure computation

Live Demo | GitHub

Install

npm install @aumiqx/scroll

Quick Start

import{ScrollEngine}from"@aumiqx/scroll";constengine=newScrollEngine({mass: 1.2,friction: 0.95,min: 0,max: 3000,zones: [{start: 0,end: 600,friction: 0.85},// slow hero{start: 600,end: 1200,friction: 0.97},// fast gallery{start: 1200,end: 1800,snap: true},// snap pricing],magnets: [{position: 1500,strength: 0.4,range: 120},],});// On wheel events:element.addEventListener("wheel",(e)=>{e.preventDefault();engine.applyForce(e.deltaY*0.3);},{passive: false});// On every frame:functiontick(){conststate=engine.tick();element.style.transform=`translateY(${-state.position}px)`;requestAnimationFrame(tick);}tick();

Why?

Every website on Earth uses identical scroll physics. Same mass, same friction, same inertia. The browser's scroll engine is a black box you can't modify.

This library replaces it with a physics engine where every parameter is yours.

FeatureNative ScrollLenisGSAP ScrollTrigger@aumiqx/scroll
Custom frictionNoPartialNoPer-section
Magnetic snapCSS onlyNoNoConfigurable
Custom massNoNoNoYes
Bounce wallsPlatform-specificNoNoElastic
Pure computationN/ADOM-dependentDOM-dependentNo DOM

API

new ScrollEngine(options?)

Create a scroll physics engine.

constengine=newScrollEngine({mass: 1.2,// scroll inertia (higher = more momentum)friction: 0.95,// velocity decay per frame (0.80-0.99)min: 0,// scroll bounds minimummax: 3000,// scroll bounds maximumzones: [],// per-section friction overridesmagnets: [],// magnetic snap pointswalls: [],// custom bounce points});

engine.applyForce(delta)

Apply external force from wheel/touch events. Divided by mass internally.

element.addEventListener("wheel",(e)=>{engine.applyForce(e.deltaY*0.3);});

engine.tick()

Advance physics by one frame. Call on every requestAnimationFrame.

conststate=engine.tick();// state.position - current scroll position (px)// state.velocity - current speed (px/frame)// state.activeZone - which zone index is active (-1 if none)// state.nearestMagnet - magnet index in range (null if none)// state.isBouncing - whether hitting a wall

engine.setPosition(pos)

Jump to a position. Resets velocity.

engine.setPosition(1200);// teleport to pricing section

engine.configure(options)

Update physics at runtime.

// User enables "reduced motion"engine.configure({mass: 0.5,friction: 0.85});

engine.position / engine.velocity

Read current state.

Zone Configuration

interfaceScrollZone{start: number;// zone start (px)end: number;// zone end (px)friction?: number;// override friction (0.80-0.99)snap?: boolean;// pull to center when slow}

Examples:

zones: [{start: 0,end: 600,friction: 0.82},// hero: heavy, cinematic{start: 600,end: 1200,friction: 0.975},// gallery: light, momentum{start: 1200,end: 1800,snap: true},// pricing: magnetic center{start: 1800,end: 2400,friction: 0.80},// cta: maximum resistance]

Magnet Configuration

interfaceScrollMagnet{position: number;// target position (px)strength: number;// pull force (0-1)range: number;// activation radius (px)}

Example:

magnets: [{position: 1500,strength: 0.4,range: 120},// pricing{position: 2100,strength: 0.5,range: 100},// cta]

Use Cases

  • Storytelling landing pages - hero is slow, gallery is fast, CTA snaps
  • WebGL camera control - mass and inertia create cinematic camera movement
  • Reading experiences - long articles automatically slow scroll down
  • E-commerce - product listings glide, checkout anchors
  • Data visualization - scroll drives chart progression with zone-based pacing
  • Scroll-driven games - scroll IS the game input with custom physics

How It Works

Each frame:

  1. Force - wheel/touch input divided by mass
  2. Friction - velocity multiplied by zone-specific friction (0.80-0.99)
  3. Magnets - nearby magnets apply pull proportional to proximity
  4. Position - updated by velocity, clamped to bounds with bounce
velocity += force / mass
velocity *= zoneFriction
velocity += magnetPull
position += velocity

License

MIT

About

Programmable scroll physics engine. Per-section friction, magnetic snap, configurable mass. ~4KB, zero dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages