javascript - Sidebar that follows scroll, but scrolls self, if taller than viewport -


(hey, first post longtime lurker :)

i've built simple sidebar 'absolute-to-fixed' trick stay on screen, take in account scenarios, sidebar higher viewport.

so came idea. starts in above:

  • on page load, sidebar drawn @ starting location, distance viewport top.
  • when user scrolls page, sidebar moves content
  • if sidebar fits viewport vertically, fixes top

but here gets more dynamic:

  • if sidebar taller viewport, continues scroll content until bottom of sidebar reached, , fixes there. top of sidebar scrolls beyond top of viewport.

  • when user scrolls towards page top, sidebar moves content until top of sidebar reached, , fixes there. bottom of sidebar scrolls beyond bottom of viewport.

this way sidebar reacts scrolling usual, while sticking around close enough find on long pages.

any pointers examples, or jquery- friendly code snippets/guidelines appreciated.

i had exact idea project, here's example of how implement it

http://jsfiddle.net/ryanmaxwell/25qae/


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -