
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
sticky-scroller
Advanced tools
Scroll your very long sticky positioned sidebar.
![]()
position: sticky is a very useful and interesting CSS3 feature. When scrolling
page, navbar/header/sidebar can magically switch between static and fixed
position. Usually, height of sticky element is smaller than viewport height. It
means you do not need to scroll the content of sticky element.
However, when you have a sidebar with a long list and it is not able to show all
content in viewport, position: sticky cannot help with this. When you scroll
the page, sidebar content doesn't scroll.
You may come up with a quick solution:
sidebar {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
height: 100vh;
overflow-y: auto;
}
Then you can scroll sidebar content, right?

Here are some disadvantages of above solution:
So how JavaScript can make a difference?
JavaScript syncronize scrolling of page and sticky sidebar.
overflow-y: hidden for
floating container.overflow-y: hidden, content can still be scrolled by JavaScript.window, you can point mouse cursor anywhere on the
page, or even use keyboard.Install with NPM.
npm install sticky-scroller --save
Import with Webpack or Browserify.
// Old way
var StickyScroller = require("sticky-scroller");
// New way
import StickyScroller from "sticky-scroller";
Download latest release and unpack, you will need dist/sticky-scroller.js.
Link it in HTML.
<!-- Option 1: Vanilla JavaScript -->
<script src="path/to/sticky-scroller/dist/sticky-scroller.js"></script>
<!-- Option 2: use jQuery plugin (not recommended) -->
<script src="path/to/sticky-scroller/dist/sticky-scroller.jquery.js"></script>
AMD package is build for you if you prefer RequireJS.
<script src="path/to/sticky-scroller/dist/sticky-scroller.amd.js"></script>
requirejs(["StickyScroller"], function(StickyScroller) {
// What ever you like
});
UMD module is placed at dist/sticky-scroller.umd.js
Change top and height (or max-height) to whatever you like. Make sure it
is within viewport. You don't need overflow-y: hidden since it will be added
by JavaScript.
.my-sidebar {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
height: 100vh;
}
const scroller = new StickyScroller(".my-sidebar");
If you prefer to use it with jQuery:
$(".my-sidebar").stickyScroller();
Constructor of main controller.
string | HTMLElementThe sticky element. Use a selector string or HTMLElement object.
ObjectNo option available now.
Copyright 2018 Guo Yunhe.
GNU General Public License version 3 or later.
FAQs
Scroll your very long sticky positioned sidebar
We found that sticky-scroller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.