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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:11:47+00:00 2026-06-15T14:11:47+00:00

Trying to apply and image transition effect to a fixed bg image for a

  • 0

Trying to apply and image transition effect to a fixed bg image for a particular div. Currently looks like –

#top-header {
background: #FFF url('/images/image001.jpg') no-repeat top center fixed; 
width: 100%;height: 540px;
}   

<div id="top-header"></div>

I am aware that CSS3 allows for multiple bg images. Since images are being called through my CSS is it possible to apply javascript to the current div to achieve a fade in/out transition effect?

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-15T14:11:48+00:00Added an answer on June 15, 2026 at 2:11 pm

    You can do a lot with JavaScript and CSS however this is a very solved problem with many options for basically showing slideshows. So it might be best to look at one of those. But let’s try it anyway!

    HTML:

    <div id="slideshow"></div>​
    

    CSS:

    #slideshow {
        border: 1px solid gray;
        height: 330px;
        width: 592px;
        opacity: 0;
    }
    

    ​
    JavaScript:

    $(document).ready(function() {
        var timeToDisplay = 2000;
        var opacityChangeDelay = 50;
        var opacityChangeAmount = 0.05;
    
        var slideshow = $('#slideshow');
        var urls = [
           'http://sipi.usc.edu/database/preview/aerials/2.1.07.png',
           'http://sipi.usc.edu/database/preview/aerials/2.1.06.png',
           'http://sipi.usc.edu/database/preview/aerials/2.1.12.png'
        ];
    
        var index = 0;
    
        var transition = function() {
            var url = urls[index];
    
            slideshow.css('background-image', 'url(' + url + ')');
    
            index = index + 1;
            if (index > urls.length - 1) {
                index = 0;
            }
        };
    
        var fadeIn = function(opacity) {
            opacity = opacity + opacityChangeAmount;
    
            slideshow.css('opacity', opacity);
    
            if (opacity >= 1) {
                slideshow.trigger('fadeIn-complete');
                return;
            }
            setTimeout(function() {
                fadeIn(opacity);
            }, opacityChangeDelay);
        };
    
        var fadeOut = function(opacity) {
            opacity = opacity - opacityChangeAmount;
    
            slideshow.css('opacity', opacity);
    
            if (opacity <= 0) {
                slideshow.trigger('fadeOut-complete');
                return;
            }
            setTimeout(function() {
                fadeOut(opacity);
            }, opacityChangeDelay);
        };
    
        slideshow.on('fadeOut-complete', function(event) {
            transition();
            fadeIn(0);
        });
    
        slideshow.on('display-complete', function(event) {
            fadeOut(1);
        });
    
        slideshow.on('fadeIn-complete', function(event) {
            setTimeout(function() {
                slideshow.trigger('display-complete');
            }, timeToDisplay);
        });
    
        transition();
        fadeIn(0);
    });​
    

    Demo: jsfiddle

    Of course, jQuery already has fadeIn and fadeOut so we can simplify our code by using them:

    $(document).ready(function() {
        var timeToDisplay = 2000;
    
        var slideshow = $('#slideshow');
        var urls = [
           'http://sipi.usc.edu/database/preview/aerials/2.1.07.png',
           'http://sipi.usc.edu/database/preview/aerials/2.1.06.png',
           'http://sipi.usc.edu/database/preview/aerials/2.1.12.png'
        ];
    
        var index = 0;
        var transition = function() {
            var url = urls[index];
    
            slideshow.css('background-image', 'url(' + url + ')');
    
            index = index + 1;
            if (index > urls.length - 1) {
                index = 0;
            }
        };
    
        var run = function() {
            transition();
            slideshow.fadeIn('slow', function() {
                setTimeout(function() {
                    slideshow.fadeOut('slow', run);
                }, timeToDisplay);
            });
        }
    
        run();
    });​
    

    Demo: jsfiddle

    We could also use slideDown and slideUp: jsfiddle

    So why not just use this? Well you could however I’m aware of one obvious flaw: we start the slideshow before making sure all the images have been downloaded by the browser. We should fix that. No doubt there are similar issues we may have overlooked but the choice is yours on what to use.

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

Sidebar

Related Questions

I'm trying to apply border-radius effect on a particular div. The code I used
I'm trying to apply background image (same one) to two div tags: .abc {
I am trying to apply a background image hover effect on each row in
I have two CIImages. I'm trying to apply a CGAffineTransformation to the top image,
I'm trying to apply a CSS image rollover on a Wordpress header logo. I
I am trying to apply effect (sepia, brightness, bloom and other image effects if
I have this div that I am trying to apply line-height like so... .social
I am trying to apply a background-image to a li element. <ul> <li class=maintablink>&nbsp;</li>
I am using CSS to apply a background image to a div tag that
I am trying to apply a background image for a button inside the form.

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.