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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:04:24+00:00 2026-05-22T20:04:24+00:00

I have seen several solutions which determine when an element is visible in the

  • 0

I have seen several solutions which determine when an element is visible in the viewport whilst scrolling the page, but I haven’t seen any which do this for elements that are contained in a scrolling container div as in the example here.

How would I detect the items as they scroll into view via the scrolling div? And by contrast how would I detect them if they fell out of view. In all cases the overflow elements are not hidden at the outset.

HTML

    <div id="mainContainer" class="main">
        <div id="scrollContainer"class="scroller">
            <div id="picturesContainer"class="holder">
                <div id="pictureContainer1" class="picture position1">
                pictureContainer1</div>

                <div id="pictureContainer2" class="picture position2">
                pictureContainer2</div>
                <div id="pictureContainer3" class="picture position3">
                pictureContainer3</div>
                <div id="pictureContainer4" class="picture position4">
                pictureContainer4</div>
                <div id="pictureContainer5" class="picture position5">
                pictureContainer5</div>
                <div id="pictureContainer6" class="picture position6">
                pictureContainer6</div>
                <div id="pictureContainer7" class="picture position7">
                pictureContainer7</div>
                <div id="pictureContainer8" class="picture position8">
                pictureContainer8</div>
                <div id="pictureContainer9" class="picture position9">
                pictureContainer9</div>
            </div>

        </div>
    </div>

CSS

    .main{
        position:absolute;
        top:0px;
        left:0px;
        height: 200px;
        width:200px;
        background-color: grey;
        border: 1px solid black;
    }

    .scroller{
        position:absolute;
        top:0px;
        left:0px;
        height: 250px;
        width:250px;
        background-color: lightblue;
        border: 1px solid black;
        overflow: scroll;
    }

    .picture{
        position:absolute;
        height: 200px;
        width: 200px;
        background-color: lightyellow;
        border: 1px solid black;
    }

    .position1{
        top:0px;
        left:0px;
    }

    .position2{
        top:0px;
        left:200px;
    }

    .position3{
        top:0px;
        left:400px;
    }

    .position4{
        top:200px;
        left:0px;
    }

    .position5{
        top:200px;
        left:200px;
    }

    .position6{
        top:200px;
        left:400px;
    }

    .position7{
        top:400px;
        left:0px;
    }

    .position8{
        top:400px;
        left:200px;
    }

    .position9{
        top:400px;
        left:400px;
    }

    .holder{
        position:absolute;
        top:0px;
        left:0px;
        width:600px;
        height:600px;
        background-color:lightgreen;
    }
  • 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-22T20:04:25+00:00Added an answer on May 22, 2026 at 8:04 pm

    include jQuery library on page first.

    function getObjDims(obj){
        if (!obj) return false;
        var off = $(obj).offset();
        var t = {
            top:off.top,
            left:off.left,
            width:$(obj).width(),
            height:$(obj).height()
        };
        return {x1:t.left, y1:t.top, x2:t.left+t.width,y2:t.top+t.height}
    };
    function testInside(pic,box){
        var d=getObjDims(pic);
        return (box.x1<=d.x1 && box.y1<=d.y1 && box.x2>=d.x2 && box.y2>=d.y2)?1:-1;
    };
    $(document).ready(function(){
        var inside={};
        var port=$('#scrollContainer');
        var box=getObjDims(port);
        $(window).resize(function(){
            box=getObjDims(port);
        });
        $(port).scroll(function(){      
            var str=[];
            $('.picture').each(function(i){
                var oldState = inside[this.id]!=undefined?inside[this.id]:0;            
                var newState = testInside(this,box);
                inside[this.id]=newState;
                if (oldState!=newState)
                    switch (newState){
                        case 1:str.push(this.id);break;// go IN
                        case -1: break;// go OUT
                    }
            });
            $('#picStatus').text(str.join(', '));
        });
    });
    

    Add in HTML for results output:

    <div style='margin-top:280px;'>Pictures in window (numbers):</div>
    <div id='picStatus'></div>
    

    It is code based on object’s coords, witch are recalculated on scroll event. There are some things to know. IE and, seems to be, Opera takes into consideration width and height of scrollbars themselves, that demands curtain code tuning. I just have suggested solution direction and did not spent much time for debugging this.

    And yet, maybe will be useful following (from jquery api about offset):

    Note: jQuery does not support getting
    the offset coordinates of hidden
    elements or accounting for borders,
    margins, or padding set on the body
    element.

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

Sidebar

Related Questions

I have seen examples of printing from a windows application but I have not
I have seen Solutions created in Visual Studio 2008 cannot be opened in Visual
I have seen the official demos on lwjgl.org but I would like to see
I've seen several similar scenarios explained here but not my particular one. I wonder
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
I have seen several Questions comparing different ECommerce CMS's: Prestashop compared to Zen-Cart and
I have a method which returns a bool value, with several exit points. However,
I have seen in several SAAS sites where people store data and the site
I have seen several modules (example: Iterator::Simple ) that make use of Perl's angle

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.