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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:23:46+00:00 2026-06-12T00:23:46+00:00

I am using this code. When it changes the image, the image fades out

  • 0

I am using this code. When it changes the image, the image fades out and then the other image fades in, and in the meanwhile I can see the background color, which I don’t want to see. Is there any simple way to fade images but at the same time fade in the next image, or another jQuery effect like slide the images? I just don’t want to see the background color.

<script type="text/javascript">
$(document).ready(function(){
    var imgArr = new Array( // relative paths of images
        'css/images/main_img.jpg',
        'css/images/main_img_2.jpg',
        'css/images/main_img_3.jpg',
        'css/images/main_img_4.jpg',
        'css/images/main_img_5.jpg'
    );

    var preloadArr = new Array();
    var i;

    /* preload images */
    for(i = 0; i < imgArr.length; i++){
        preloadArr[i] = new Image();
        preloadArr[i].src = imgArr[i];
    }

    var currImg = 1;
    var intID = setInterval(changeImg, 6000);
    //added this so that the first image is always the first from the array
    $('#main_content').css('background','url(' + preloadArr[0].src +') top center no-repeat');
    /* Main IMG */
    function changeImg(){
        $('#main_content').animate({opacity: 0}, 1000, function(){
            $(this).css('background','url(' + preloadArr[currImg++%preloadArr.length].src +') top center no-repeat');
        }).animate({opacity: 1}, 1000);
    }
});
</script>
  • 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-12T00:23:48+00:00Added an answer on June 12, 2026 at 12:23 am

    Since you are changing the css background you can’t do this against a single element.

    You could achieve this with another div which would hold the next background image (before your content fades out) and would be put under your #main_content element using none static css position states and z-index property.

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

Sidebar

Related Questions

I have a simple slideshow which automatticlly changes the image using setInterval every 5
Im using this code to change the src attribute of an image tag (using
i'm using this code below to drag an image across the screen. The one
I'm currently using this code to change my page's css3 background when you hover
I have tried to change the onClick image of a button using this code
I'm trying to update/change contact ringtone using this code: ContentValues values = new ContentValues();
To change the language on my website I've been using ressources and this code:
Using this code, i am able to send a notification to my own device.
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:

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.