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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:37:11+00:00 2026-05-12T20:37:11+00:00

I have 2 divs and one is nested in the other. I want to

  • 0

I have 2 divs and one is nested in the other. I want to get the child div position relative to browser window. The use case is this: when user scroll down browser, I want to detect the position of the child div and if it is 100px above the bottom of the browser window, I want to fade it out slowly.

How do I do that with jQuery? The 2 divs have relative position or absolution position but not fixed position.

  • 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-12T20:37:12+00:00Added an answer on May 12, 2026 at 8:37 pm

    Try this:

    $(window).scroll(function () {
     var distanceFromBottom = 100;
     if ( ( $("#outerdiv").offset().top + $("#innerdiv").height() - $(window).scrollTop() ) > $(window).height() - distanceFromBottom ) {
      $("#innerdiv").fadeOut("slow");
     } else {
      $("#innerdiv").fadeIn("slow");
     }
    })
    

    You didn’t state if you wanted the #innerdiv to fade back in if greater than 100 pixels from the bottom, but I wrote this assuming that you did… In this case, you would need to detect the offset of the #outerdiv if you want the #innerdiv to fade back in as an invisible element has no position.

    If you don’t want the #innerdiv to fade back in then change the if statement to look at the #innerdiv element and remove the else portion of the function.


    Edit: Looking at your example page, I’m guessing you wanted this effect to work on the music player. Since, it’s probably not the best idea to fade or slowly hide an embedded object using jQuery – it just doesn’t animate well – so, I just did it abruptly. The above script will still work, but as you can see in the revision below, you don’t have to use 2 Divs, I used the div and the embedded object within it. The outer div should closely wrap the inner div for this script to work, so you can’t use the div with id “container-msg” in this case.

    $(window).scroll(function () {
     var distanceFromBottom = 100;
     if ( ( $(".windowMediaPlayer").offset().top + $(".windowMediaPlayer object").height() - $(window).scrollTop() ) > $(window).height() - distanceFromBottom ) {
      $(".windowMediaPlayer object").hide();
     } else {
      $(".windowMediaPlayer object").show();
     }
    })
    

    I modified your example and saved it to this pastebin so you can see it working.

    Edit: Oops, you said you wanted it to disappear when it got closer to the bottom… I just changed the “<” to “>” and now it should do what you want. I updated the pastebin code too.

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

Sidebar

Related Questions

i have 10 divs one after the other that I want to organize in
I have two divs, one nested inside of the other. The parent element has
I have a div which contains two nested divs, one that specifies a height
I have two inner divs which are nested inside a wrapper div. I want
I have 2 divs aligned one below the other. These are nested inside another
I have 2 nested divs and outer one has width:100% <div id=#outer style=width:100%; border:1px>
I have two divs that are not nested, one below the other. They are
I keep finding that if I have nested divs inside each other, and one
I have a div with two nested divs inside, the (float:left) one is the
I have two DIVs: One DIV dynamically changes size based on the browser (responsive

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.