-1

Not sure if this is possible, but I'm trying to add a fade in to a jquery css change. I tried using the css transition attribute too, to no avail.

Here's how far I've got, but it's not working.

HTML:

<section id="primary" class="home-section-hero">
    <div class="bcg" data-anchor-target="#primary">
        <ul>
            <li data-pid="1">
                <img src=“folder/path”>
            </li>
        </ul>
    </div> <!-- .bcg -->
</section> <!-- #primary -->

CSS:

#primary {
    height: 100%;
    width: 100%;
}

#primary .bcg {
    background: url("images/miscreated-bg.jpg");
    background-attachment: fixed;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    box-shadow: 10px 5px 15px rgba(0, 0, 0, 0.5) inset;
    height: 100%;
    text-shadow: 1px 0 1px rgba(0, 0, 0, 0.5);
    width: 100%;
    -webkit-transition-delay: 500ms;
    -moz-transition-delay: 500ms;
    -o-transition-delay: 500ms;
    transition-delay: 500ms;
}

jQuery:

$( "li[data-pid='1'] img" ).click(function() {
    $( "#primary .bcg" ).fadeIn( "slow", function() {
        $(this).css( "background", "url(http://ericbrockmanwebsites.com/dev7/wp-content/themes/AntCas/player-images/bgs/Titanic-bg.jpg) no-repeat fixed center center / cover  rgba(0, 0, 0, 0)");
    });
});

Any insights?

Eric Brockman
  • 824
  • 2
  • 10
  • 37

1 Answers1

0

You cannot set a transition in between 2 background-image.

You need to set them on top of eachothers into differents containers, than could fade with opacity and z-index for instance: here an example : http://codepen.io/gcyrillus/pen/DJdja

basis is

body:before, body:after {
  content:'';
  top:0;
  left:0;
  bottom:0;
  right:0;
  position:absolute;
  z-index:1;
    background-size: cover;
  animation:bgfade 10s infinite;
  animation-direction: alternate;
  opacity:1;
}

With the body background, you can fade in/out 3 different image. via js, jQuery or CSS.

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129