我试图让这个按钮与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>
&#13;
我希望它能够在屏幕上(在Z轴上)向上和向下反弹。
答案 0 :(得分:8)
您可以使用关键帧动画来设置按钮缩放比例的动画并使其反弹:
.order {
position: absolute;
top: 50px;
left: 50px;
width: 75px;
line-height: 75px;
text-align:center;
opacity: 1;
background: green;
color:#fff;
border-radius:50%;
-webkit-animation: bounce .3s infinite alternate;
-moz-animation: bounce .3s infinite alternate;
animation: bounce .3s infinite alternate;
}
@-webkit-keyframes bounce {
to { -webkit-transform: scale(1.2); }
}
@-moz-keyframes bounce {
to { -moz-transform: scale(1.2); }
}
@keyframes bounce {
to { transform: scale(1.2); }
}
&#13;
<div class="order">Order</div>
&#13;
如果你想在一些&#34;反弹&#34;之后停止动画,你可以使用animation-iteration-count
(使用偶数次迭代,否则动画将在结尾处捕捉):
.order {
position: absolute;
top: 50px;
left: 50px;
width: 75px;
line-height: 75px;
text-align:center;
opacity: 1;
background: green;
color:#fff;
border-radius:50%;
-webkit-animation: bounce .3s infinite alternate;
-moz-animation: bounce .3s infinite alternate;
animation: bounce .3s infinite alternate;
-webkit-animation-iteration-count: 8;
-moz-animation-iteration-count: 8;
animation-iteration-count: 8;
}
@-webkit-keyframes bounce {
to { -webkit-transform: scale(1.2); }
}
@-moz-keyframes bounce {
to { -moz-transform: scale(1.2); }
}
@keyframes bounce {
to { transform: scale(1.2); }
}
&#13;
<div class="order">Order</div>
&#13;
答案 1 :(得分:1)
web-tiki发布的答案是最好用的,我仍然采用不同的方法becoz你已经使用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;
}
}
&#13;
<div class="order"></div>
&#13;
修改强>
要进一步添加,您还可以将left和top设置为38px,以便将其设置为 按钮看起来不像原来的位置看到这个 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 0.5s 2;
}
/* Standard syntax */
@keyframes mymove {
0% {
height: 75px;
width: 75px;
left: 50px;
top: 50px;
}
50% {
height: 100px;
width: 100px;
left: 38px;
top: 38px;
}
100% {
height: 75px;
width: 75px;
left: 50px;
top: 50px;
}
}
&#13;
<div class="order"></div>
&#13;
答案 2 :(得分:1)
试试这个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>
答案 3 :(得分:0)
您可以像以下一样制作动画(反弹):
<强> CSS:强>
.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