- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I want my div containing facebook like button, google + and tweet to move as in this link
so that when i scroll the div move up and then stays stationary at the top of the page as i scroll.
its an easy task with jquery.
you have to listen for the window scroll event and when the window has scrolled a certain amount you change the position of the element from absolute to fixed;
$(window).scroll(function(){
var scroll = $(window).scrollTop();
if( scroll== 300){
$(‘.box’).css(‘position’,’fixed’);
}
if(scroll < 300){
$(‘.box’).css(‘position’,’absolute’);
}
})
You’re close, but the `==` should be `>` for it to work. If your website is responsive you’ll also want to call that function on resize, in case that number 300 (awesome movie btw) you have there changes. Speaking of which, it’s better not to hardcode that number in the script but read it from another element. Which brings me to: [epic demo](http://codepen.io/CrocoDillon/pen/kFoJm) :)
you’re right , i just played with the code a little and came up with the numbers