browser โฉ event โฉ type โฉ scroll โฉ example โฉ scroll progress on body
update the progress bar's width when body.onscroll. (body's height is fixed)
replit โฉ scroll progress (1) , require -> Node+ext, Element+boxes
const { log } = console // โญ๏ธ import import { $ } from './js/ext/Node_ext.js'; // Node + ext import { viewport } from './js/ext/Element+boxes.js'; // Element + boxes // -------------------------------------------------------------------- // elements const html = document.documentElement; // <HTML> const body = document.body; // <BODY> const bar = $("#progress"); // Node + ext const info = $("#info"); const content = $('#content'); content.textContent = "supercali fragilisti cexpiali docious ".repeat(200); // โญ๏ธ event handlers // ------------------------------------------------------- // body.onscroll (โญ๏ธ windown/html.onscroll also worksโ) body.addEventListener("scroll", () => { const maxScroll = body.scrollBox.height - body.paddingBox.height; // Element+boxes const currentScroll = body.scrollBox.y; // Element+boxes const percent = (currentScroll / maxScroll) * 100; // update UI bar.style.width = `${percent}%`; bar.textContent = `${percent.toFixed(0)}%`; info.textContent = `scroll amout: ${currentScroll} / max: ${maxScroll}`; }, true); // โญ๏ธ capturing: true (importantโ) // -> see: https://ayase.moe/2018/11/20/scroll-event/
๐ CSS
html, body { height: 300px; overflow: scroll; /* โญ๏ธ ๅฟ ้ html, body ๅ ฉ่ ้ฝ่จญๅฎๆๆๆ๏ผไธ็ฅ็บไฝ๏ผ */ }
scroll progress - body's height is automatic.
ไฝ ๆไธ็ฅ้็ scroll ไบไปถ๏ผไธบไปไน scroll ไบไปถไผๅคฑๆ๏ผ โญ๏ธ
Eloquent JS โฉ Scroll Events
HTML vs Body: How to Set Width and Height for Full Page Size
Event โฉ
Element: scroll event
Element: scrollend event - when scroll has ended.
Document: scroll event
Last updated 1 year ago