The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

how to control position of div?

  • # April 7, 2013 at 7:25 am

    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.

    # April 7, 2013 at 8:02 am

    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;

    var scroll = $(window).scrollTop();
    if( scroll== 300){

    if(scroll < 300){

    # April 7, 2013 at 8:36 am

    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]( :)

    # April 7, 2013 at 8:45 am

    you’re right , i just played with the code a little and came up with the numbers

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed