SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to fix element position after some scroll

    I want to fix element position after some scroll.

    Ex : http://www.quicksprout.com/2012/11/2...irst-customer/

    When you scrolling down you can see "Neil increased TechCrunch's traffic by 30% within 2 months" banner is fixed. I want to add that type of banner to my blog.

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    The simplest way is to add a class to the body with javascript when the scroll is greater than some number.
    e.g. using jQuery
    Code:
    $(window).scroll(function(){
      $(document.body).toggleClass('sticky', window.pageYOffset > 200);
    })
    Then you just add position fixed to the thing within .sticky


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •