CSS背景交叉淡化问题

时间:2017-01-07 14:33:07

标签: css image webkit css-transitions transition

我遇到的问题是我的后台交叉淡化不能正常工作。 也许有人能够告诉我我做错了什么? :) 这是脚本:

HTML:

<div class="bg">
    <div class="backgroundchange">
        <div class="bgimg" id="bg1">
            <div class="title centerV">
                <div>
                    <div class="text">
                        <h1>Malarstwo</h1>
                        <p>Beaty Domanskiej</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="bgimg" id="bg2">
            <div class="title centerV">
                <div>
                    <div class="text">
                        <h1>Malarstwo</h1>
                        <p>Beaty Domanskiej</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="bgimg" id="bg3">
            <div class="title centerV">
                <div>
                    <div class="text">
                        <h1>Malarstwo</h1>
                        <p>Beaty Domanskiej</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS:

.bgimg {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    position: absolute;
    background-repeat: no-repeat;
    background-position: center center;
    transform: scale(1);
    -webkit-box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    -moz-box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

#bg1 {
    background-image: url("../img/gallery/slonecz.jpg");
}

#bg2 {
    background-image: url("../img/gallery/motyl.jpg");
}

#bg3 {
    background-image: url("../img/gallery/slonecz.jpg");
}

@keyframes backgroundchangeFadeInOut {
    0% {
        opacity: 1;
    }

    17% {
        opacity: 1;
    }

    25% {
        opacity: 0;
    }

    92% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@-webkit-keyframes backgroundchangeFadeInOut {
    0% {
        opacity: 1;
    }

    17% {
        opacity: 1;
    }

    25% {
        opacity: 0;
    }

    92% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

#backgroundchange div:nth-of-type(1) {
    animation-delay: 8s;
    -webkit-animation-delay: 8s;
}

#backgroundchange div:nth-of-type(2) {
    animation-delay: 6s;
    -webkit-animation-delay: 6s;
}

#backgroundchange div:nth-of-type(3) {
    animation-delay: 4s;
    -webkit-animation-delay: 4s;
}

#backgroundchange div {
    animation-name: backgroundchangeFadeInOut;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-duration: 8s;
    -webkit-animation-name: backgroundchangeFadeInOut;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-duration: 8s;
}

因此,我可以看到第一个背景设置,但它永远不会交叉进入下一个背景设置。

2 个答案:

答案 0 :(得分:0)

您无法在不设置css @keyframe的情况下设置动画。

将关键帧添加到您的所有动画中这是一个示例:

 @-webkit-keyframes backgroundchangeFadeInOut{
            0% {transform: translateY(-100%); opacity: 0;}
            80% {transform: translateY(40%);}
            100% {transform: translateY(0%); opacity: 1;}
        }

答案 1 :(得分:0)

你想要这样吗?

以下是适用于我的笔记本电脑的代码:

CSS:

.bgimg {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    position: absolute;
    background-repeat: no-repeat;
    background-position: center center;
    transform: scale(1);
    -webkit-box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    -moz-box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    box-shadow: inset 4px 1px 77px 40px rgba(0,0,0,0.78);
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background-image: url("../img/gallery/slonecz.jpg");
    animation-name: backgroundchangeFadeInOut;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-duration: 8s;
    -webkit-animation-name: backgroundchangeFadeInOut;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-duration: 8s;
}

@keyframes backgroundchangeFadeInOut {
    0% {
       background-image: url("../img/gallery/slonecz.jpg");
    }
    50% {
       background-image: url("../img/gallery/motyl.jpg");
    }
    100% {
       background-image: url("../img/gallery/slonecz.jpg");
   }
}

HTML:

<div class="bg">
    <div class="backgroundchange">
        <div class="bgimg" id="bg1">
            <div class="title centerV">
                <div>
                    <div class="text">
                        <h1>Malarstwo</h1>
                        <p>Beaty Domanskiej</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>