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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:26:18+00:00 2026-06-01T20:26:18+00:00

Really beating my head in with this one. I’ve got a variable amount of

  • 0

Really beating my head in with this one. I’ve got a variable amount of images to be loaded into the page in groups of 5. On page load, I’m trying to load the first 5 and each group after that will be added in by clicking on a link.

My logic is this:

  • make an array of all the list elements on page load

  • pass the first 10 of the array into a function that converts the li to an image and fades it into the page on window load

  • pass additional groups of 5 from the array on user click of a load more button

my code that doesn’t follow the above logic but does convert the li’s and fade them in is below:

see full commented mess on jsfiddle:
http://jsfiddle.net/danielredwood/qntMg/

thanks for your help!

function buildImg() {
    $('.userGallery li').each(function(){
        var loc = $(this).find('a').attr('href'),
            ttl = $(this).find('a').attr('title'),
            img = $('.userGallery').append($('<img/>', { class: 'user', src: loc, alt: ttl })),
            usr = $('.user');

        $(this).remove();

        usr.each(function(i){
            $(this).delay(200*i).animate({ opacity:1 },400);
        });
    });
}

    var elm = $('.userGallery li'),
        cnt = 0,
        tns = [];

    for(i=0;i<elm.length;i++){
       if(cnt==10){
         buildImg(tns);
         tns=[];   
       }
       tns[cnt++]=elm[i].image;
    }

    buildImg(tns);
  • 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-01T20:26:19+00:00Added an answer on June 1, 2026 at 8:26 pm

    Here’s a bit simpler way to do this. To explain, buildImg() finds all the desired links and creates image objects for each one and puts them in an array.

    loadMore() loads the next 10 images into the gallery and initiates their .fadeIn() animation. loadMore() is called once initially (to load the first 10 images) and then subsequently when the loadMore button is clicked to load the next 5 each time it’s pressed.

    Because you only had 10 images in your jsFiddle, I duplicated them just so you could see how it works with more than 10 images.

    Everything is encapsulated in a document.ready handler so that it starts when the DOM is loaded and so that our globals aren’t really globals (so they are inside a function block).

    $(document).ready(function() {
        var imgInfo = [];
        var imgCntr = 0;
        function buildImg() {
            $('li a').each(function(){
                var img = new Image();
                img.src = this.href;
                img.alt = this.title;
                img.className = 'user';
                img.style.display = "none";
                imgInfo.push(img);
            });
        }
    
        function loadMore(num) {
            var gallery = $('.userGallery');
            var delay = 0;
            for (len = Math.min(imgInfo.length, imgCntr + num); imgCntr < len; imgCntr++) {
                gallery.append(imgInfo[imgCntr]);
                $(imgInfo[imgCntr]).delay(delay).fadeIn(400);
                delay += 400;
            }
        }
    
        buildImg();
        loadMore(10);
    
        $(".loadMore").click(function() {
            loadMore(5);
            return(false);
        });
    });​
    

    Working demo here: http://jsfiddle.net/jfriend00/h2GVz/

    Here’s a bit more involved version that doesn’t start animating the images until they are loaded in case they take longer to load than their scheduled animation time. You may not need this extra complication, but I was interested in how to do it so I wrote it: http://jsfiddle.net/jfriend00/WAuuB/

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

Sidebar

Related Questions

Really ripping my hair out on this one. I have a JAAS Authentication Provider
I must be doing something really stupid here, but I've been beating my head
So I have beating my head against the wall on this. I feel like
Really confused with this one. I am selecting an 'a' element by its class
okay, I am beating myself up over this. I am need to load a
Really simple problem: I want to split a connection string into its keyword /
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
Really wish i was God, then I would understand what this means: The element
I really can't believe I couldn't find a clear answer to this... How do
This is probably really obvious to most of you but i am new to

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.