Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 12, 2020 02:54 pm GMT

How I Put the Scroll Percentage in the Browser Title Bar

Some nice trickery from Knut Melvr.

Ultimately the trick boils down to figuring out how far you’ve scrolled on the page and changing the title to show it, like:

document.title = `${percent}% ${post.title}`

Knut’s trick assumes React and installing an additional library. I’m sure that library does all kinds of smart stuff, but if you’re looking to do this “vanilla” style, I’d probably rock something like this…

const percentLabel = document.querySelector("#percent");const originalTitle = document.title;window.addEventListener("scroll", () ={  

Read article “How I Put the Scroll Percentage in the Browser Title Bar”

The post How I Put the Scroll Percentage in the Browser Title Bar appeared first on CSS-Tricks.


Original Link: https://www.knutmelvaer.no/blog/2020/05/how-i-put-the-scroll-percentage-in-the-title-bar/

Share this article:    Share on Facebook
View Full Article

CSS Tricks

A Web Design Community curated by Chris Coyier

More About this Source Visit CSS Tricks