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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:09:28+00:00 2026-06-09T16:09:28+00:00

I am changing my background image from this code jQuery(window).load(function(){ var images = [‘blaa.jpg’,’sdsd.jpg’];

  • 0

I am changing my background image from this code

jQuery(window).load(function(){
var images = ['blaa.jpg','sdsd.jpg'];
var i = 0;
setInterval(function(){

    jQuery('#absolute-c').css('background-image', function() {
        if (i >= images.length) {
            i=0;
        }
        return 'url(' + images[i++] + ')';      
    });
}, 3000);
})

how do .animate and load first background without delay. due to setInterval my first background also show after 3 sec

  • 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-09T16:09:30+00:00Added an answer on June 9, 2026 at 4:09 pm

    You can do create a function for this and use it in the setInterval:

    jQuery(window).load(function(){
        var images = ['blaa.jpg','sdsd.jpg'];
        var i = 0;
    
        function changeBackground() {
            jQuery('#absolute-c').css('background-image', function() {
                if (i >= images.length) {
                    i=0;
                }
                return 'url(' + images[i++] + ')';      
            });
        }
        // Call it on the first time
        changeBackground();
        // Set an interval to continue
        setInterval(changeBackground, 3000);
    });
    

    Another solution, and I think is much better, is to use setTimeout instead:

    jQuery(window).load(function(){
        var images = ['blaa.jpg','sdsd.jpg'];
        var i = 0;
        var timeoutVar;
    
        function changeBackground() {
            clearTimeout(timeoutVar); // just to be sure it will run only once at a time
    
            jQuery('#absolute-c').css('background-image', function() {
                if (i >= images.length) {
                    i=0;
                }
                return 'url(' + images[i++] + ')';      
            });
    
            // call the setTimeout every time to repeat the function
            timeoutVar = setTimeout(changeBackground, 3000);
        }
    
        // Call it on the first time and it will repeat
        changeBackground();        
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code, changing a background image for a jQ plugin, Works fine
I have this line of jQuery: $(#colorimage).css('background','url(images/bw.jpg)'); First question: the way that this is
When I put a background image in my anchor, my anchor is changing it's
I want to generate tooltip based on a dynamically changing background image in css.
This is my little CSS style: #languages_menu { background: url('/images/langs.png') repeat-y; bottom: 40px; font-size:
I'm changing my background-image css property using Mootools: $(document.body).setStyle('background-image','url(' + pBackground + ')'); And
background-position: -200px 0; one site says it crops an image from the bottom and
I am changing the background color of the cells when the user has made
I was changing the background of the Actionbar in my App and to make
I changed the background colour of the spinner.After changing the bg colour the down

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.