Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:16:02+00:00 2026-06-11T11:16:02+00:00

My header is set to a width of 920px centered and using the code

  • 0

My header is set to a width of 920px centered and using the code below the header becomes fixed and changes opacity when the user scrolls. I have acheived my desired effect pretty easily although when the change happens instant. I’m wondering if i can make the change fade into place? I’ve tried using CSS3 Transitions with no luck.

      <script>
  $(function() {

    // grab the initial top offset of the navigation 
    var sticky_navigation_offset_top = $('header').offset().top;

    // our function that decides weather the navigation bar should have "fixed" css position or not.
    var sticky_navigation = function(){
        var scroll_top = $(window).scrollTop(); // our current vertical position from the top

        // if we've scrolled more than the navigation, change its position to fixed to stick to top,
        // otherwise change it back to relative
        if (scroll_top > sticky_navigation_offset_top) { 


            $('header').css({ 'position': 'fixed', 'position': 'fixed', 'opacity':0.8,  'top':0, 'left':0 });

        } else {
            $('header').css({ 'position': 'relative' }); 
        }   

    };

    // run our function on load
    sticky_navigation();

    // and run it again every time you scroll
    $(window).scroll(function() {
         sticky_navigation();
    });

});
  </script>

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:16:03+00:00Added an answer on June 11, 2026 at 11:16 am

    You can place your styles into 2 separate classes and use jQuery UI’s switchClass()

    switchClass( remove, add, [duration] )

    Switches from the class defined in the first argument to the class
    defined as second argument, using an optional transition.

    Add some style classes:

    style1{
        position: fixed;
        opacity: 0.8;
        top: 0;
        left: 0;
    }
    
    style2{
        position: relative;
    }
    

    Switch between them:

    if (scroll_top > sticky_navigation_offset_top) {
        $('header').switchClass("style2", "style1", 300);
    } else {
        $('header').switchClass("style1", "style2", 300);
    }​
    

    Alternatively you can look further into CSS3 transforms. I have not used them myself yet but they may be able to achieve what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look at the html and css below. I have set the width of the
I currently have a simple header set up in HTML, and am using CSS
I set the UIwebview as a header in UITableview . UIWebview height and width
I'm setting up a very simple fixed-liquid layout. The header is set to 100%,
I’m trying to set the header search path in Xcode 4 (using LLVM 2.0
I have problem when I try to set a background to .header - nothing
I have a header that is larger than the width of the page so
I have a crude header bar set up on fiddler: http://jsfiddle.net/bCJts/ It looks ok
At the moment I have this (standard) code which gives me a full-width background
I want to set header column width for grid view. I tried HeaderStyle-Width=30px .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.