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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:07:04+00:00 2026-06-13T18:07:04+00:00

I want to crossfade/transition background images through hovering the element. Is is possible? I

  • 0

I want to crossfade/transition background images through hovering the element. Is is possible?
I have a DIV element that has a background image but when you hover it, the background image changes with a transition/crossfade effect. On my Stylesheet i have assigned a class for hover state.

Here is the normal or non-hover state of DIV.

#crossfade DIV{
    width: 100px;
    height: 100px;
    background-image: url('img/bg.jpg');
}

Below is the hover state class of DIV.

#crossfade DIV.hovered{
    background-image: url('img/bg-1.jpg');
}

Then my jquery script below:

$(function(){
    $('#crossfade').find('DIV').hover(function(){
        $(this).addClass('hovered');
    }, function(){
        $(this).removeClass('hovered');
    });
});

My script just simple switch the background image. Now what i want is to give it a transition effect or more like fadeIn/fadeOut effect. Like as the previous background image is fading out, the next background image is also fading In.

Any idea how to do this? Is it possible?

Thanks 🙂

  • 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-13T18:07:07+00:00Added an answer on June 13, 2026 at 6:07 pm

    I spent quite some time troubleshooting this as it interested me as well. Learnt a lot so thought I’d share it with you.

    First: I don’t believe you can cross-fade background images using addClass and removeClass because you can’t logistically fade an element in and out at the same time. (If I’m wrong about this please someone school me).

    Just so that you know that I know what you’re wanting, I successfully got the following to work:

    $(".div-bkgrnd-1").hover(function() {
        $(this).fadeOut("slow",function() {
            $(this).addClass('div-bkgrnd-2').fadeIn("slow",function() {
                $(this).removeClass('div-bkgrnd-1');
            });
        });
    });
    

    However, this DOESN’T resolve your issue, which is creating a cross-fade of 2 images.

    You will see that the fadeOut runs first, then the new class is added, then the fadeIn is run, and the first class is removed. You can’t run the fadeOut and fadeIn (which would create the cross-fade you’re looking for) at the same time because if you remove the first class before the fadeOut is finished, it interrupts the animation.

    Here is a solution that I believe will work for you.

    HTML:

    <div id="div1"> <!-- with CSS background-image applied -->
        <img id="img" />
    </div>
    

    jQuery:

    $("#div1").hover(function() {
        $("#img").fadeToggle("slow");
    });
    

    Note: Be sure to target the div for your hover function; targeting the image results in some bizarre behaviour.

    (This solution assumes you wanted the image to crossfade when you hover and then crossfade back to the original when you un-hover. Changing the function to fadeOut will work as a once-off if that’s what you want).

    If you were specifying background images because you need other content to sit in front, this is easily solved using z-index and a containing div (plus the jQuery above).

    HTML:

    <div id="container">
        <div id="div1">
            <img id="img" />
        </div>
        <div id="div2>
            Some content here to appear over the top of "div1".
        </div>
    </div>
    

    CSS:

    #div1 {
        z-index: 1;
        position: absolute;
        background-image: image1;
    }
    
    #div2 {
        z-index: 2;
        position: relative;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I have to two images on a page that I want to cross
I have an image map in one div and I want to replace the
I'm aware of various image crossfade plugins, but i need to crossfade text. Like,
I have a website where the background image is stretched to fit the entire
want to create a temporary table that has an auto_increment field plus a field
want to drag element to specific div and if not dragged to this div
I want to crossfade between two different UIImages but for a reason i cannot
I have a set of 10 images, and I want to create an animation
I'm trying to create a transparent (no button background) ImageButton that has a custom
I'm trying to do a crossfade effect, and I have TransitionManager.start(imageHolder, {type:Fade, direction:Transition.IN, duration:0.75});

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.