使用CSS3使按钮反弹

6ioyuze2  于 2023-01-06  发布在  CSS3
关注(0)|答案(4)|浏览(225)

我正在尝试使用CSS3使此按钮反弹

.order {
  position: absolute;
  top: 50px;
  left: 50px;
  width: 75px;
  line-height: 75px;
  text-align:center;
  opacity: 1;
  background: green;
  color:#fff;
  border-radius:50%;
}
<div class="order">Order</div>

我希望它向上和向下朝着屏幕(在Z轴上)反弹。

ht4b089n

ht4b089n1#

您可以使用关键帧动画来设置缩放比例的动画,并使按钮反弹

.order {
  position: absolute;
  top: 50px;
  left: 50px;
  width: 75px;
  line-height: 75px;
  text-align:center;
  opacity: 1;
  background: green;
  color:#fff;
  border-radius:50%;
  animation: bounce .3s infinite alternate;
}
@keyframes bounce {
  to { transform: scale(1.2); }
}
<div class="order">Order</div>

迭代计数:

如果要在多次"反弹"后停止动画,可以使用animation-iteration-count(使用偶数次迭代,否则动画将在最后一次迭代时捕捉):
一个二个一个一个

kknvjkwl

kknvjkwl2#

试试这个CSS

.order {
    background:url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png");
      background-size: cover;
      position: absolute;
      top:50px;
      left:50px;
      width: 75px;
      height: 75px;
      z-index:1;
      opacity:1;

}

@keyframes fade {
    from { top:40px;
      left:40px;
      width: 100px;
      height: 100px; }
    50% { top:50px;
      left:50px;
      width: 75px;
      height: 75px; }
    to { top:40px;
      left:40px;
      width: 100px;
      height: 100px; }
}

@-webkit-keyframes fade {
    from { top:40px;
      left:40px;
      width: 100px;
      height: 100px; }
    50% { top:50px;
      left:50px;
      width: 75px;
      height: 75px; }
    to { top:40px;
      left:40px;
      width: 100px;
      height: 100px; }
}

.blink {
    animation:fade 1000ms infinite;
    -webkit-animation:fade 1000ms infinite;
}

试试这个html

<div class="order blink"></div>
cigdeys3

cigdeys33#

答案张贴的web-tiki,将是最好的一个使用,但我有一个不同的方法,因为你已经使用position:absolute
看到这个FIDDLE你需要动画高度和宽度的按钮使用关键帧。

.order {
  background: url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png") no-repeat;
  position: absolute;
  background-size: cover;
  top: 50px;
  left: 50px;
  width: 75px;
  height: 75px;
  z-index: 1;
  opacity: 1;
  -webkit-animation: mymove 1s infinite;
  /* Chrome, Safari, Opera */
  animation: mymove 1s infinite;
}
/* Chrome, Safari, Opera */

@-webkit-keyframes mymove {
  0% {
    height: 75px;
    width: 75px;
  }
  50% {
    height: 100px;
    width: 100px;
  }
  100% {
    height: 75px;
    width: 75px;
  }
}
/* Standard syntax */

@keyframes mymove {
  0% {
    height: 75px;
    width: 75px;
  }
  50% {
    height: 100px;
    width: 100px;
  }
  100% {
    height: 75px;
    width: 75px;
  }
}
<div class="order"></div>
    • 编辑:**

为了进一步添加,你也可以动画左和顶部到38px,使按钮看起来不像偏离原来的位置看到这个Fiddle
一个二个一个一个

w6mmgewl

w6mmgewl4#

您可以设置动画(反弹),如下所示:

    • 中央支助组:**
.order {
    background:url("http://onestudio.id-staging.com/_BUILD/Dominos/BANNERS/C3%20Digital%20Midweek%20Rescue/Wide%20Skyscraper/images/order.png");
      position: absolute;
      top:50px;
      left:50px;
      width: 75px;
      height: 75px;
      z-index:1;
      opacity:1;
      animation: myfirst 2s infinite;
      -webkit-animation: myfirst 2s infinite; 
}

    @-webkit-@keyframes myfirst {

    0% {
    transform: scale(1);
  }
  50% {
   transform: scale(1.5);
  }
  100% {
   transform: scale(1);
  }
}

@keyframes myfirst {

    0% {
    transform: scale(1);
  }
  50% {
   transform: scale(1.5);
  }
  100% {
   transform: scale(1);
  }
}

检查Fiddle

相关问题