jQuery - DIV to move with scrolling motion and sti

2019-01-23 06:40发布

There may be already a jQuery plugin which can achieve this, but I can't find one to do exactly what I'm after. If there is, just point me to the tutorial, thanks.

My problem I have is that I have very long page content, and my sidebar is not visible when you are scrolled near the bottom of the page.

So I would like to make my #sidebar div to stick to the top and bottom of my browser window as you scroll up and down the page.

My sidebar height is longer than your typical screen resolution, so I need the bottom of sidebar to sticky to the bottom of the browser window as well as the top of the browser.

So as you begin to scroll down, the side bar will scroll like normal, but when you reach the end the sidebar, it sticks and will not scroll, and as you begin to scroll up, the sidebar will follow until the top of sidebar reaches the browser, then it sticks. Vice Versa.

Is this possible?

I have created a jsfiddle of simple design layout which is central. I have added a dotted border to the sidebar so you now where the sidebar should stick.

http://jsfiddle.net/motocomdigital/7ey9g/5/

Any advice, or you know a online tutorial or demo, would most awesome!


UPDATE

Please see this attempt by @Darek Rossman

http://jsfiddle.net/dKDJz/4/

He's got the basic idea working. But the scrolling up, causes it to snap to the top. I need the sidebar to be fluid with the scrolling up/down motion. But sticking to the either the top or bottom of the window. It should also not be fixed positioned when the header/footer are in viewport, so it does not overlay.

Thanks

7条回答
啃猪蹄的小仙女
2楼-- · 2019-01-23 07:40

I have updated the jsfiddle http://jsfiddle.net/7ey9g/76/ with my solution.

The sidebar should remain in place at the top when the window is larger than the sidebar and fix to the bottom when the sidebar is larger.

查看更多
登录 后发表回答