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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:27:15+00:00 2026-05-18T05:27:15+00:00

I can’t get the actually LazyLoad plugin to work for me so I am

  • 0

I can’t get the actually LazyLoad plugin to work for me so I am trying to write my own with. Currently I have a list of images loading inside of a DIV. They are pulled by a PHP query to the mysql database. The DIV scroll is set to auto. The code I am using is:

<div id="b1" style="overflow:auto;">
<?PHP $result = mysql_query("SELECT * FROM images");

while($row = mysql_fetch_assoc($result)) {

echo "<img src='$row[photo]' style='display:none'> <br>";

}

</div>

<script type="text/javascript">
function imgCheck() {
var position        = $("img").offset().top;            
var scrollCheck       = $("#b1").scrollTop() + $("#b1").height();
if ( scrollCheck > position) {
  $("img").fadeIn("fast");
   }


$("#b1").scroll( function() { imgCheck() } );
</script>

Although this is not quite working for me. Could anyone help me out or shoot out some suggestions?

  • 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-18T05:27:16+00:00Added an answer on May 18, 2026 at 5:27 am

    A couple of things:

    • As the others have already said, your code has syntax errors – both with the PHP and the Javascript.
    • If you use display: none, the elements will not take up any height, thus causing the entire thing to become unscrollable and fail.
    • The first few elements should be visible without the user having to start scrolling

    Taking these into consideration, we can try writing this this way:

    // Cache the containing element and it's height
    var b1 = $('#b1'),
        h = b1.height();
    
    // Insert 20 img's - simulating server-side code
    for(var i = 0; i < 20; i++){
        $('<img />', {
            src: 'http://placehold.it/100x100',
            alt: '',
            class: 'hidden',
            width: 100,
            height: 100
            // visibility: hidden to retain it's size
        }).css('visibility', 'hidden').appendTo(b1);
    }
    
    b1.scroll(function(){
        // Loop through only hidden images
        $('img.hidden').each(function(){
            // $(this).position().top calculates the offset to the parent
            // So scrolling is already taken care of here
            if(h > $(this).position().top){
                // Remove class, set visibility back to visible,
                // then hide and fade in image
                $(this).css('visibility', 'visible')
                    .hide()
                    .removeClass('hidden')
                    .fadeIn(300);
            } else {
                // No need to check the rest - everything below this image
                // will always evaluate to false - so we exit out of the each loop
                return false;
            }
        });
        // Trigger once to show the first few images
    }).trigger('scroll');
    

    See a demo of this here: http://jsfiddle.net/yijiang/eXSXm/2

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

Sidebar

Related Questions

Can anyone tell me what i am doing wrong? I am trying to get
Can anyone help me trying to find out why this doesn't work. The brushes
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can anyone please advice how can I have value of i in the following
I have a jquery bug and I've been looking for hours now, I can't
Can't figure out how to do this in a pretty way : I have
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can't work out a way to make an array of buttons in android. This

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.