When browsing websites, I often see that on some websites, some content in the side column is fixed at that position after scrolling to the top of the page, and no longer scrolls with the scroll bar. This effect is called "sidebar scrolling." It's useful for content that you don't want to scroll off the page.
There are many ways to implement sidebar scrolling. There are two common ones. These two methods are clearly introduced in an article written by NEOEASE. One is to use jQuery. Implementation, this method is obviously a burden for those websites that usually do not need to load the jQuery library (jQuery is getting bigger and bigger now...). Another method is to write the effect through native javascript. This method is much lighter than the previous one. However, I am still not satisfied. The files written by native JavaScript are more than 4K, which is still too complicated for someone like me who puts simplicity first. So is there a simpler way to implement it?
The answer is of course yes. Details are introduced below.
Let’s talk about the html file first (of course it can also be a dynamic file, there is always html code in it)