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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:47:06+00:00 2026-06-11T23:47:06+00:00

I have a div that will have a few images in it. I would

  • 0

I have a div that will have a few images in it. I would like for the images to disappear when the user scrolls to the point where the top or bottom edges of the image are just about to be hidden by the parent div. The structure is like this:

<div class="parent">
   <img/>
   <img/>
</div>

My goal is to have the image fade out when its top or bottom edges start to be hidden by the parent div, and then have it fade back in when its scrolled in to full view.

I am using jQuery and listening to the div scroll event to check the img offset().top, and once it hits a top value that is not in view, I hide the image.

But this seems to take up a lot of CPU time since I have to iterate through the images with each scroll event. On top of that, even though I call hide() on the img, it doesn’t hide it at all (put a break point in just to make sure it was getting called, and it was). Is there an accurate way to do this?

EDIT: Thanks to mcpDESIGNS, I was needed to use position() instead of offset(). Also, it looks like hide() wont work since display is set to none. So I switched to visibility:hidden and it works as expected.

EDIT2: Just as a note, here is the js I am using, pretty much what mcpDesigns had suggested

old

var display = $("div");

display.scroll(function () {

    var avatars = $("div > img");
    console.log("************************");
    avatars.each(function (index) {
        console.log($(this).offset().top);

        if ($(this).offset().top < 40)
            $(this).hide();
        else {
            $(this).show();
        }
    });
});

new

var display = $("div");

display.scroll(function () {

    var avatars = $("div > img");
    console.log("************************");
    avatars.each(function (index) {
        console.log($(this).position().top);

        if ($(this).position().top < 0)
            $(this).css("visibility", "hidden")//.hide();
        else {
            $(this).css("visibility", "")//.show();
        }
    });
});
  • 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-11T23:47:07+00:00Added an answer on June 11, 2026 at 11:47 pm

    You’ll need to do a lot of calculations based on each image and whether it’s position is either negative (meaning top of the parent scrollable div), or the same # as the height of your scrollable div.

    ​$('.parent').scroll(function () {            
        console.log($('img').position().top);
    
        // if ( negative top position || same#asDivheight) { fadeIn / out, etc }
    });​
    

    Play around with that, but that’s basically the jist of it.

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

Sidebar

Related Questions

I have a div box (black) that will display a few different product images
I have div that contains quite a few images. When I say quite a
Suppose I have div and inside that div I have few form controls like
I have a div that will serve as container to other element, I have
I have a div that has a span inside that will display a message
I am trying to have an advertisement block/div that will be switched to a
I have an animation on a partially hidden div container that will execute when
I have created some JQuery that will expand a div 'popup' on hover and
I have a div that is absolutely positioned from the top left corner of
I have a few div boxes that are using position:fixed and I use a

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.