jquery animate sticky

Discussion in 'jQuery' started by bartolay13, May 7, 2012.

  1. #1
    $('.container').animate({top: "0"}, 500);
    HTML:
    im using this jquery simple animate which is showing on top of the whole page, my question is, i want the animation dynamic by the users window. i mean if they scroll down the page i want the animation not going back to the top but to its current view.

    regards,
     
    bartolay13, May 7, 2012 IP
  2. OMGCarlos

    OMGCarlos Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, so to understand correctly you basically just want the container to follow the window right?

    What you'll need to do is add bind the window's scroll event, and update the containers top-position like so:
    $(window).scroll(function(e){
            $('.container').offset({top: e.currentTarget.pageYOffset});
        });
    Code (markup):
    Here's a fiddle: http://jsfiddle.net/9cQWg/
     
    OMGCarlos, May 10, 2012 IP