Mastodon: floating back-to-top button
Adds a floating button in the bottom-right corner that smoothly scrolls the timeline to the top.
Code to copy
// Add a floating "Back to top" button on the timeline
(function () {
if (document.getElementById('jz-mst-top')) { return; }
var btn = document.createElement('button');
btn.id = 'jz-mst-top';
btn.textContent = 'Top';
btn.setAttribute('aria-label', 'Scroll to top');
btn.style.cssText = 'position:fixed;right:24px;bottom:24px;z-index:9999;background:#6364ff;color:#fff;border:none;padding:10px 14px;border-radius:24px;font-weight:600;box-shadow:0 4px 12px rgba(0,0,0,0.25);cursor:pointer;opacity:0;transition:opacity .2s;';
document.body.appendChild(btn);
function scroller() {
return document.querySelector('.columns-area__panels__main .scrollable') || document.querySelector('.column .scrollable') || document.scrollingElement;
}
btn.addEventListener('click', function () {
var s = scroller();
if (s) { s.scrollTo({ top: 0, behavior: 'smooth' }); }
});
function check() {
var s = scroller();
var y = s ? (s.scrollTop || 0) : (window.scrollY || 0);
btn.style.opacity = y > 600 ? '1' : '0';
}
document.addEventListener('scroll', check, true);
setInterval(check, 800);
})();
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.