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 6993657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:47:32+00:00 2026-05-27T19:47:32+00:00

jsfiddle: http://jsfiddle.net/MFUw3/5/ jQuery: function showDiv() { if ($(window).scrollTop() > 610) { $(.a).css({position: fixed, top:

  • 0

jsfiddle: http://jsfiddle.net/MFUw3/5/

jQuery:

function showDiv() {
    if ($(window).scrollTop() > 610) {
        $(".a").css({"position": "fixed", "top": "10px"});
    } else {
        $(".a").css({"position": "relative", "top": "0px"});
    }
}
$(window).scroll(showDiv);
showDiv();

HTML:

<div>
    <div class="a">
        A
    </div>
    <div class="b">
        B
    </div>
</div>

I want to make it so when the user has scrolled past div “B” (A and B are out of sight), then div “A” will fade in and fix itself to the top of the browser.

When you scroll up and div “B” is back in sight, I want div “A” to fade out and reposition itself back to where it was originally.

My code currently does just this, EXCEPT it doesn’t do fading.

I’ve tried messing around with .is(":visible"), .is(":hidden"), .hide(); so that I can use fadeIn(); and fadeOut();, but no matter what I try, I can’t figure it out, and I know this isn’t efficient in the first place. There’s probably some way to detect if it’s passed a div instead of passed a certain coordinate?

  • 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-05-27T19:47:33+00:00Added an answer on May 27, 2026 at 7:47 pm

    Here’s something that should suit your needs:

    function showDiv() {
        if ($(window).scrollTop() > 610 && $('.a').data('positioned') == 'false') {
            $(".a").hide().css({"position": "fixed", "top": "10px"}).fadeIn().data('positioned', 'true');
        } else if ($(window).scrollTop() <= 610 && $('.a').data('positioned') == 'true') {
            $(".a").fadeOut(function() {
                $(this).css({"position": "relative", "top": "0px"}).show();
            }).data('positioned', 'false');
        }
    }
    $(window).scroll(showDiv);
    $('.a').data('positioned', 'false');
    

    And the link to the working example: http://jsfiddle.net/MFUw3/10/

    Edit: I have added the code improvements suggested by Sparky672 and the (initially omitted) fadeout.

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

Sidebar

Related Questions

http://jsfiddle.net/JamesKyle/y7hBQ/ I'm making a simple jquery counting function that adds the following classes: First
Why isn't jQuery being applied to dynamically created elements? Here is jsFiddle: http://jsfiddle.net/Y5RuC/19/ When
I'm struggling a bit with this CSS-issue: http://jsfiddle.net/timkl/JbEX8/ I want two divs to align
In this jsFiddle http://jsfiddle.net/littlesandra88/RBU8K/ have I the following code function addRemove(id) { alert(1); $('#'+id).toggle(function()
I have the following code at JSfiddle: http://jsfiddle.net/ACG2D/ $(document).ready(function() { $('.testThis').click(function() { $('.regexValidation').each(function() {
http://jsfiddle.net/yTkTd/ Another function with a class works perfectly, but this one seems to be
Consider this jsfiddle: http://fiddle.jshell.net/maple/JbEJN/show/ (this is the result window, in order for replaceState to
Website test page: http://www.lantiis.com/indexold.html jsFiddle: http://jsfiddle.net/Guhb4/7/ I received help with the jQuery and it
var x = window.Something; alert(window.x) when i try this code in jsfiddle http://jsfiddle.net/XJEGU/ ,
Having some issues trying to create a fixed header layout for this jsfiddle: http://jsfiddle.net/4xk4D/107/

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.