CSS 3d动画循环变换尺寸

时间:2019-02-18 20:19:17

标签: html css html5 css3

我正在尝试使div与http://red-button.webflow.io/完全相同 但没有得到准确的结果

我的代码在下面

@keyframes scale-div {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1)
  }
  100% {
    transform: scale(0);
  }  
}
@keyframes scale-border {
  0% {
    width: 200px;
    height: 35px;
  }
  50% {
    width: 250px;
    height: 50px;
  }
  100% {
    width: 200px;
    height: 35px;
  }  
}



.scale {
  position: absolute;
  border-radius: 0%;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);

  animation: scale-border 2s steps(300, end) infinite;
 content: '';
   border-radius: 5px;
    background: #d70b0b;
    box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, .33);
    font-family: Montserrat, sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
    padding: 9px 15px;
    color: white;
    border: 0;
    line-height: inherit;
    text-decoration: none;
    cursor: pointer;
    text-align: center;

line-height: -moz-block-height;
}
 <div class="scale">Get A Free Estimate</div>

我取得了70%的结果,但没有达到100%

需要与示例链接完全相同的动画,文本和框大小转换

1 个答案:

答案 0 :(得分:2)

只需使用如下比例动画:

@keyframes scale-div {
  to {
    transform:translate(-50%, -50%) scale3d(1.05,1.05,1);
  }
}

.scale {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-style:preserve-3d;
  animation: scale-div 0.5s infinite linear alternate;
  border-radius: 5px;
  background: #d70b0b;
  box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, .33);
  font-family: Montserrat, sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-block;
  padding: 9px 15px;
  color: white;
  border: 0;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
<div class="scale">Get A Free Estimate</div>

为避免对文本造成不良影响,您可以考虑使用translateZ和perspective:

@keyframes scale-div {
  to {
    transform:perspective(100px) translate(-50%, -50%) translateZ(5px);
  }
}

.scale {
  position: absolute;
  top: 50%;
  left: 50%;
  transform:perspective(100px) translate(-50%, -50%);
  transform-style:preserve-3d;
  animation: scale-div 0.5s infinite linear alternate;
  border-radius: 5px;
  background: #d70b0b;
  box-shadow: 1px 1px 3px 0 rgba(0, 0, 0, .33);
  font-family: Montserrat, sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-block;
  padding: 9px 15px;
  color: white;
  border: 0;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
<div class="scale">Get A Free Estimate</div>