简体   繁体   English

如何为背景图像的不透明度设置动画?

[英]How can I do to animate opacity of an background image?

在此处输入图片说明

I'm trying to do a little animation on my header, I use the pink red lines and I want to disappear and appear on a keyframe, but when I apply my styles, all the container is animated (both box), I only want apply this animation on the pink lines.我正在尝试在我的标题上做一些动画,我使用粉红色的红色线条,我想消失并出现在关键帧上,但是当我应用我的样式时,所有的容器都是动画的(两个框),我只想要将此动画应用于粉红色线条。 My code is has follow:我的代码如下:

HTML HTML

<div class="row m-0 section-1 position-relative">
      <div style="background-color: #da2f9c;" class="col-12 col-md-5 pt-5 text-center mb-5 ">
      </div>
      <div id="header" class="col-12 col-md-7 position-relative">
        <img class="img-fluid position-absolute" src="./assets/img/header/1.png">
        <img class="img-fluid position-absolute" id="pc-base-glow2" src="./assets/img/header/2.png">
        <img class="img-fluid position-absolute" src="./assets/img/header/3.png" alt="">
        <img class="img-fluid position-absolute" id="core-down" src="./assets/img/header/4.png" alt="">
        <img class="img-fluid position-absolute" id="core-up" src="./assets/img/header/5.png">
        <img class="img-fluid position-absolute" src="./assets/img/header/6.png">
      </div>
      <div class="row position-absolute diagonal">
        <div class="col-12 p-0">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="#ffffff" fill-opacity="1" d="M0,128L1440,320L1440,320L0,320Z"></path></svg>
        </div>
      </div>
    </div>

CSS CSS

/* Esperimental header */
.section-1 {
  background-color: #1b154e;
}
#header {
  /* position: relative; */
  height: 100vh;
  background-image: url('../img/header/0.png');
  background-repeat: no-repeat;
  background-position: right bottom;
  /* background-size: contain; */
  animation-duration: 5s;
  animation-name: base-lines;
  animation-iteration-count: infinite;
}

#header img {
  /* position: absolute; */
  right: 0;
  bottom: 12%;
}

How can I do only apply aopacity to my pink lines?我怎样才能只对我的粉红色线条应用 aopacity?

Try this:尝试这个:

    #header {
        position: relative;
        height: 100vh;
    }
    #header:after {
        content : "";
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background-image: url('../img/header/0.png'); 
        width: 100%;
        height: 100%;
        opacity : 1;
        z-index: -1;
        -webkit-animation: changeBg 5s infinite;
        animation: changeBg 5s infinite;
        animation-direction: alternate;
        background-repeat: no-repeat;
        background-position: right bottom;
        animation-duration: 5s;
        animation-name: base-lines;
        animation-iteration-count: infinite;
    }

    @keyframes changeBg {
       0%   {opacity: 0.00;}
       100% {opacity: 1.00;}
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery,如何为背景中的图像设置覆盖不透明度动画 - jQuery, how to animate overlay opacity, with image in background 如何为 HTML EMAIL 设置不透明度低的背景图像 - How do I set background image with low opacity for HTML EMAIL 如何设置身体背景的图像不透明度 - How can I set the image opacity for body background 如何在jQuery中更改.animate()之后的背景图像不透明度? - How to change background-image opacity after .animate() in jquery? 如何在 css 中平滑悬停时为背景图像大小设置动画? - How do I animate background image size on hover smoothly in css? 如何使用 css 为身体的背景图像设置动画 - How can I animate Background Image of body wth css 我想使用伪元素在代码中使用背景图像的不透明度。 我怎么做? - I want to play with the opacity of the background image in the code using pseudo element. How do I do that? 当图像名称不同时,如何设置不透明度为50%的div元素背景图像 - How can I set a div elements background image, with 50% opacity, when image name can vary 如何在不影响背景颜色的情况下更改背景图像的不透明度? - How can I change the background image opacity without affecting the background color? 如何更改背景色的不透明度? - How can I change the opacity of a background colour?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM