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

  • SEARCH
  • Home
  • 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 8812999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:44:07+00:00 2026-06-14T03:44:07+00:00

Okay, I know it seems like I’ve asked this question already, for which @adeneo

  • 0

Okay, I know it seems like I’ve asked this question already, for which @adeneo had previously answered and apreciated, however I am rattling my brains because I just can’t get this to work.

I’m trying to make my ‘fixed’ positioned header ‘fadeTo’ 0.5 Opacity when scrolled down and fade back to full opaqueness (‘opacity’: 1.0) when the user scrolls back to the top?

Here’s what I have:

$(window).on('scroll', function() {
if ($(this).scrollTop() > 50) {
$("#header").fadeTo(400, 1);
}else{
$("#header").fadeTo(400, 0.5);

}
});

At the moment, using this code only seems to make it ‘fadeTo’ 0.5 opacity when scrolled down but it then won’t fade back to full opaqueness (opacity: 1.0) when scrolled back to the top.

Please help!

  • 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-14T03:44:09+00:00Added an answer on June 14, 2026 at 3:44 am

    One of the problems is that you’re executing an animation of 400ms for every time your user scrolls the page, this generates a very long queue of effects which have no visible effect, e.g. animating to 1 opacity for each time the scroll event fires with scrollTop > 50, adding a very long queue of invisible effects until the fading out effect takes place.

    A simple way to remedy that is using .stop(true) before executing the fadeTo, this way the element effects queue will be always cleared before executing the given animation.

    $(window).on('scroll', function() {
        if ($(this).scrollTop() > 50) {
            $("#header").stop(true).fadeTo(400, 0.5);
        } else {
            $("#header").stop(true).fadeTo(400, 1);
        }
    });
    

    Fiddle

    But even so you will still be executing animations unnecessarily, so I’d recommend using .data to store the faded state and only animate when necessary:

    $(window).on('scroll', function() {
        var header = $("#header");
        if ($(this).scrollTop() > 50) {
            if (!header.data('faded')) header.data('faded', 1).stop(true).fadeTo(400, 0.5);
        } else if (header.data('faded')) {
            header.data('faded', 0).stop(true).fadeTo(400, 1);
        }
    });
    

    Fiddle

    ps. I’ve inverted your opacity values as your question’s code’s logic didn’t correspond to your desired behavior.

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

Sidebar

Related Questions

Okay i know this has been asked a lot but it seems that none
Okay I know this is a really lame question because Starbasic is a really
Okay, I know questions like this exist in multiple forms across StackOverflow and other
Okay, I know this is a Noob question but I cant see to get
Okay; sorry I know this isn't a programming question as such, but it was
Okay, so first, I have searched for this everywhere but it seems like every
Okay, this has made me feel a little peevish because it seems like it
Okay I know there are a lot of questions about this and a lot
Okay, I know that 1) this is probably not possible with CSS alone and
Okay, I know it is weird but when I put this code between <head

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.