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

  • Home
  • SEARCH
  • 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 6338603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:28:44+00:00 2026-05-24T19:28:44+00:00

I am trying to use a jQuery based Photo Stack which uses the following

  • 0

I am trying to use a jQuery based Photo Stack which uses the following codes:

$ps_albums.children('div').bind('click',function(){
    var $elem = $(this);
    var album_name = 'album' + parseInt($elem.index() + 1);
    //alert(album_name);
    var $loading     = $('<div />',{className:'loading'}); 
    $elem.append($loading);
    $ps_container.find('img').remove();
    $.get('corrective.php', {album_name:album_name} , function(data) {
        var items_count    = data.length;
        for(var i = 0; i < items_count; ++i) {
            var item_source = data[i];
            //alert(item_source);
            var cnt = 0;
            $('<img />').load(function(){
                var $image = $(this);
                ++cnt;
                resizeCenterImage($image);
                $ps_container.append($image);
                var r = Math.floor(Math.random()*41)-20;
                if(cnt < items_count) {
                    $image.css({
                        '-moz-transform'    :'rotate('+r+'deg)',
                        '-webkit-transform'    :'rotate('+r+'deg)',
                        'transform'            :'rotate('+r+'deg)'
                    });
                }
                if(cnt == items_count){
                    $loading.remove();
                    $ps_container.show();
                    $ps_close.show();
                    $ps_overlay.show();
                }
            }).attr('src',item_source);
        }
    },'json');
});

The coorective.php is as follows:

$location   = 'corrective';
$album_name = $_GET['album_name'];
$files      = glob($location . '/' . $album_name . '/*.{jpg,gif,png}', GLOB_BRACE);
$encoded    = json_encode($files);
echo $encoded;
unset($encoded);

The above javascript code shows images from the album in random order which is probably triggered by the line:

var r = Math.floor(Math.random()*41)-20;

I have changed this to:

var r = "";

Now, when the images are loaded for the first time, they are still displaying in random orders but one the second load they follow a sequential display e.g. 0001.jpg, 0002.jpg, 0003.jpg and so on.

How can I display the sequential order every time the images are loaded – even the first time?

  • 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-24T19:28:45+00:00Added an answer on May 24, 2026 at 7:28 pm

    I think the problem is the fact you append the image to the container only after is was loaded, resulting in random order indeed depending on server load and what image finished to load first. The second time, images are taken from cache.

    To fix this, change this whole block of code:

    $('<img />').load(function(){
        var $image = $(this);
        ++cnt;
        resizeCenterImage($image);
        $ps_container.append($image);
        var r = Math.floor(Math.random()*41)-20;
        if(cnt < items_count) {
            $image.css({
                '-moz-transform':'rotate('+r+'deg)',
                '-webkit-transform':'rotate('+r+'deg)',
                'transform':'rotate('+r+'deg)'
            });
        }
        if(cnt == items_count){
            $loading.remove();
            $ps_container.show();
            $ps_close.show();
            $ps_overlay.show();
        }
    }).attr('src',item_source);
    

    To this instead:

    var $image = $('<img />').attr('src',item_source);
    $ps_container.append($image);
    $image.load(function() {
        var $image = $(this);
        ++cnt;
        resizeCenterImage($image);
        if(cnt == items_count){
            $loading.remove();
            $ps_container.show();
            $ps_close.show();
            $ps_overlay.show();
        }
    });
    

    This also removed the random rotation that you don’t want.

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

Sidebar

Related Questions

I'm trying to use JQuery to show/hide div tags based on the selected index
I'm trying to use jquery to switch between three images once you click on
I'm trying to use jquery to find an item based on it's class name.
I'm trying to use jQuery to make an ajax request based on a selected
I'am trying to use a jQuery slider in a Lift based application and I
I have a standard ul-based CSS navigation menu. I'm trying to use Jquery to
I am trying to use javascript and jquery to build an HTML table based
I'm new to JQuery and trying to use it to dynamically build HTML based
I am trying to use the jQuery-based Wijmo WijMenu control with jqGrid in order
I am trying to use jQuery(#element-id).parent().addClass('some-class'); I have a structure something like this: <div

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.