1

I want to position a element next to (and follow) the middle of the scrollbar. In other words, glue a element to the middle of the scrollbar. I guess you have to dynamically get the height and position of the scrollbar and update the elements properties with setInterval for example.

Any ideas? Thanks in advance!

Viktor
  • 460
  • 2
  • 5
  • 16

1 Answers1

3

For <div id="thingy"></div>, you can make thingy stick to the middle of the scrollbar without worrying about anything to do with the scrollbar properties. Just make thingy look like:

#thingy {
     position:fixed;
     top:45%;
     bottom:45%;
     height:10%;
     right:0px;
}

That's assuming your element has a height of 10% the screen height and wants to be snug tight on the scrollbar which is on the left side of the page.

zdebruine
  • 3,687
  • 6
  • 31
  • 50
  • I can't get that to work. For me that just centers the element vertically. I want the element to start at the top where the scrollbar is when you haven't scrolled anything and then follow the position of the scrollbar. Look at this example: http://jsfiddle.net/4KAWs/1/ – Viktor Jul 09 '12 at 13:33
  • @user1216624 - ah, I see. Question misunderstood :) This will only work if you want the element to stay centered around the scrollbar... – zdebruine Jul 09 '12 at 13:38
  • @user1216624 Perhaps this post may help you: http://stackoverflow.com/questions/1022652/get-current-scroll-position-and-pass-it-as-a-variable-with-a-link – zdebruine Jul 09 '12 at 15:16