Sidebar position "semi" fixed css -


how fixed sidebar 1 containing social buttons on site:

http://www.tripwiremagazine.com/2012/11/social-media-buttons-and-icon-sets.html

i want sidebar fixed top of screen when scroll down on top of page there must absolute position stops following browser scrool.

currently using:

#sidebar { position:fixed; } 

but not give absolute position when reaching top of page.

thank you

html

<div class="wrapper"><div class="abs" id="sidebar"></div></div> 

css

.abs { position: absolute; }  .fixed { position: fixed; top: 30px !important;}  #sidebar { top: 150px; left: 0; height: 100px; width: 20px; background-color: #ccc;}  .wrapper { height: 1500px; padding: 20px;} 

jquery

 $(document).scroll(function() {     var scrollposition = $(document).scrolltop();     var scrollreference = 10;     if (scrollposition >= scrollreference) {               $("#sidebar").addclass('fixed');        } else {         $("#sidebar").removeclass('fixed');         $("#sidebar").addclass('abs');     }; }); 

demo of code:

http://jsfiddle.net/b3jz5/6/

<div class="wrapper"> 

is example of content.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -