html - 关于 :after pseudo class 的 Css 动画不透明度

标签 html css animation

我创建了以下代码,有点像加载动画。

body {
  background-color: #fafafa;
}

.container {
  width: 700px;
  height: 400px;
  background-color: white;
  margin: 0 auto;
  box-shadow: 17px 17px 45px #d1d1d1;
  text-align: center;
  vertical-align: middle;
}

.title {
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 180%;
  text-align: center;
  position: relative;
  padding-top: 20px;
  color: orangered;
}

.circle {
  height: 50px;
  width: 50px;
  border-radius: 50%;
  background-color: #d3e6e6;
  margin: 10px;
  display: inline-block;
  position: relative;
  top: 60px;
  animation: pulse 1s linear infinite alternate;
  -webkit-animation: pulse 1s linear infinite alternate;
}

.circle:after {
  content: "";
  display: inline-block;
  height: 60px;
  width: 60px;
  border-radius: 50%;
  background-color: none;
  border-style: solid;
  border-color: transparent;
  border-top-color: #71cbcb;
  border-bottom-color: #71cbcb;
  border-width: 4px;
  top: -9px;
  left: -9px;
  position: absolute;
  animation: spinny 2s linear infinite;
  -webkit-animation: spinny 2s linear infinite;
}

@keyframes spinny {
  0% {
    transform: scale(1) rotate(0deg);
    -webkit-transform: scale(1) rotate(0deg);
  }
  50% {
    transform: scale(1.2) rotate(180deg);
    -webkit-transform: scale(1.2) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
    -webkit-transform: scale(1) rotate(360deg);
  }
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
<div class="container">
  <p class="title">Spinner</p>
  <div class="circle"></div>
</div>

我希望“脉冲”动画只影响内圆而不影响边界。对于边框,我使用 :after 认为它会与实际的圆圈分开,但我想这不是因为即使脉冲动画在 .circle 的 css 中而不是 .circle:after 它仍然会影响它。

将不胜感激任何帮助。我有点卡住了 :D

最佳答案

我在 css 中有相同的更改 border-width:0px;

body {
            background-color: #fafafa;
        }

        .container {
            width: 700px;
            height: 400px;
            background-color: white;
            margin: 0 auto;
            box-shadow: 17px 17px 45px #d1d1d1;
            text-align: center;
            vertical-align: middle;
        }

        .title {
            font-family: 'Open Sans', sans-serif;
            font-weight: 600;
            font-size: 180%;
            text-align: center;
            position: relative;
            padding-top: 20px;
            color: orangered;
        }

        .circle {
            height: 50px;
            width: 50px;
            border-radius: 50%;
            background-color: #d3e6e6;
            margin: 10px;
            display: inline-block;
            position: relative;
            top: 60px;
            animation: pulse1 1s linear infinite alternate;
            -webkit-animation: pulse1 1s linear infinite alternate;
        }

        .circle:after {
            content: "";
            display: inline-block;
            height: 60px;
            width: 60px;
            border-radius: 50%;
            background-color: none;
            border-style: solid;
            border-color: transparent;
            border-top-color: #71cbcb;
            border-bottom-color: #71cbcb;
            border-width:4px;
            top: -9px;
            left: -9px;
            position: absolute;
            animation: spinny 2s linear infinite;
            -webkit-animation: spinny 2s linear infinite;

        }

        @keyframes spinny {
            0% {
                transform: scale(1) rotate(0deg);
                -webkit-transform: scale(1) rotate(0deg);
            }
            50% {
                transform: scale(1.2) rotate(180deg);
                -webkit-transform: scale(1.2) rotate(180deg);
            }
            100% {
                transform: scale(1) rotate(360deg);
                -webkit-transform: scale(1) rotate(360deg);
            }
        }

        @keyframes pulse {
           
             0% { 
                opacity: 1;
            }
            100% {
                opacity: 0;
            }
            
             @keyframes pulse1 {
           
             0% { 
                opacity: 1;
            }
            100% {
                opacity: 1;
            }
            
        }
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Animation Spinner</title>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
    <style>
    
    </style>
</head>

<body>
    <div class="container">
        <p class="title">Spinner</p>
        <div class="circle"></div>
    </div>
</body>

</html>

关于html - 关于 :after pseudo class 的 Css 动画不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46062050/

相关文章:

javascript - 如何在 HTML/CSS 中获取标签页的真实地址?

html - <th> 范围内的 CSS 样式元素

objective-c - 动画有问题

javascript - 如何扩展 Ivan Sanchez 的 Leaflet.Polyline.SnakeAnim 以支持 'snakepause' 和 'snakeplay' 事件

iphone - UISearchBar动画隐藏按钮

html - 是否可以从 'overflow: hidden' 属性中排除一个元素?

html - 是否可以触发由 minko 中的 html 事件启动的 C++ 代码?

javascript - 在事件导航项下方显示箭头

javascript - localStorage 保存和检索元素的 CSS

html - 无法删除页面底部的空白区域(移动)