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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:27:20+00:00 2026-06-14T10:27:20+00:00

This should be a simple question. When I press a button, I’d like to

  • 0

This should be a simple question. When I press a button, I’d like to fade out one image and fade in a new one. I have a button binded to this function:

function changeBackground() {
var background = document.getElementById("background");
var h_background = document.getElementById("background_hidden")

$('#background').fadeOut('slow', function() {$('#background_hidden').fadeIn('slow')});
}

In the CSS, h_background has a display: none; attribute. With this function as it is, the current image will fade out and the other one will display but it does not fade in – it shows up suddenly.

Any ideas of what I might be doing wrong?

Added a jsfiddle, but it currently does not work – trying to figure out why.
http://jsfiddle.net/qrCjA/8/

  • 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-14T10:27:21+00:00Added an answer on June 14, 2026 at 10:27 am

    I forked your fiddle and cleaned the code a little: http://jsfiddle.net/4FzqA/.

    After looking between my cleaned version and your original, the only difference was that the fiddle was set to “onDomReady” on mine, when yours is set to “onLoad”.

    Otherwise, the code should have been functional.

    window.onload = function() {
        var button = $("#fade_out").click(changeBackground);
    }
    
    function changeBackground() {
        $('#background').fadeOut('slow', function() {
            $('#background_hidden').fadeIn('slow');
        });
    }
    

    Edit: It looks like the window.onload was conflicting with the onLoad in the original fiddle, since the original fiddle didn’t work for me. When I changed window.load to document ready, all was well, so:

    $(document).ready(function() {
        var button = $("#fade_out").click(changeBackground);
    });
    

    Another edit: If the image is large, you could try waiting for it to load, but keep in mind that the load won’t trigger if pulled from cache:

    $(document).ready(function(){
       var img = new Image();
       $(img)
          .hide()
          .load(function(){
             $("body").append(this);
             $(this).fadeIn(3000);
          })
          .attr("src", "files/originals/01.jpg");
    });
    

    Taken from: Fading in large images in Chrome.

    Another edit: From the sounds of it, you might be correct in guessing that it is an issue with the image size. I updated my original fiddle (http://jsfiddle.net/4FzqA/7/) with the new images and the load. Notice that the image is loaded each time which isn’t very efficient. But it will give you an idea. Below is the JS:

    $(document).ready(function() {
        var button = $("#fade_out").click(changeBackground);
    });
    
    function changeBackground() {
        $('#background').fadeOut('slow', function () {
            $('#background_hidden')
                .attr('src', 'http://img688.imageshack.us/img688/8633/daynightm.jpg?' + (new Date()).getTime())
                .load(function () { 
                    $(this).fadeIn('slow'); 
                });  
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be very simple question. There are many programming languages out there, compiled
This is (should be) a simple question. I'd like to create a component like
This should be a simple question. I have a simple if/else statement: <?php //
This should be fairly simple question. I'm using DocX library to create new word
I think this should be a simple question to answer. I have the next
Okay, so this should be a simple question, but I'm fairly new at programming,
I have simple question. How do you press a button with your enter key?
This should be a really simple question, but I'm still having difficulty. I have
This should be a simple question, but I just can't recall the relevant API.
This should be a simple question, but I can't get it to work :(

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.