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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:58:02+00:00 2026-05-23T20:58:02+00:00

I am trying to show some random images in a div. My HTML code

  • 0

I am trying to show some random images in a div. My HTML code is like this:

<div class="sponsors">
<div id="sponsorsContent">
    <div class="spacer"></div>
    <div class="sponsorSlide" id="imgageSlide_1">
        <img alt="" src="<?php echo $this->baseUrl(); ?>/img/Sponsors/img_1.jpg" /><br />
        <span class="thumbnail-text">Image Text</span>
    </div>
    <div class="spacer"></div>
    <div class="sponsorSlide" id="imgageSlide_2">
        <img alt="" src="<?php echo $this->baseUrl(); ?>/img/Sponsors/img_2.jpg" /><br />
        <span class="thumbnail-text">Image Text</span>
    </div> ... </div></div>

I am trying to first shuffle “sponsorSlide” divs and then select 7 of them randomly. I want to show it with fadeIn and fadeOut. Generally, I’m trying this code:

$('#sponsorsContent').addClass('horizontal');
$('#sponsorsContent div').addClass('hidden').removeClass('visible');
$('#sponsorsContent .sponsorSlide').rand(7).removeClass('hidden');
setInterval(function(){
    $('#sponsorsContent').fadeOut(500);
    $('#sponsorsContent .sponsorSlide').delay(500).addClass('hidden').removeClass('visible').shuffle();
    $('#sponsorsContent .sponsorSlide').rand(7).removeClass('hidden').addClass('visible');                  
    $('#sponsorsContent').fadeIn(1500);
}, 5000);

The main problem is, when the code runs, exactly before the div fades out, you can see that the images are changing! But I want to randomize them when they are not visible!
I used different ways:

  • Delay in different positions and different parts
  • Use addClass(“bla”, 500)!
  • Show(500)/Hide(500)
  • fadeIn/fadeOut the “sponsorSlide”

FYI, I am trying to have this concept:

1- showing some random images
2- fade out
3- shuffle images
4- Select 7 random divs
5- fade in
6- go 2

Does anybody have any idea that what is my main mistake? Am I doing something in a wrong way?
I got confused and I really want to find out, which way I should try and how I can manage it to work as the way I want?

ps: It does work without fadings! But I need to fade them in and out.

  • 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-23T20:58:02+00:00Added an answer on May 23, 2026 at 8:58 pm

    You should be using a callback function in order to prevent the change from showing. If you want to hide -> change -> show, you should do it like this:

    $('#image_div').fadeOut(500, function() { //first fade out!
        $('#image_div img').attr('src', 'image.jpg'); //only then change the picture
        $('#image_div').fadeIn(500);   //and fade in
    });
    

    What comes in the function(){//code} will happen ONLY when the fadeOut() is finished.

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

Sidebar

Related Questions

I am trying to show up some HTML Special Chars like ☚ and I
I have a problem trying to show some images on my winform. On one
i am trying to show some div contents when user click a show more
I'm trying to show programmers that some captchas are too weak, and i'm breaking
I'm trying to show a 24 hours format using this line: Text='<%# Bind(Appointment, {HH:mm})
I am trying to write Classes to show some people in my skill test.
I'm currently trying out the Django framework and I would share/present/show some stuff I've
Using LaTeX , I need to show some code snippet inside a table. Here
Im trying to rezise some images that are imported from a folder. It doesent
This all goes back to some of my original questions of trying to index

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.