我试图给导航栏按钮设置动画效果,我希望li标签背景中的图像上下反弹,而文本(图像)保持不动。背景图像动画
我知道有没有直接的CSS方法来动画背景图像,但我试图考虑到这一点。
请参阅以下的jsfiddle链接,我的代码:
#Home
{
position: absolute;
width:125px;
height:100px;
background: transparent url('Images/Icons/HomeIcon.png') no-repeat top center;
-webkit-animation-fill-mode:both;
-moz-animation-fill-mode:both;
-ms-animation-fill-mode:both;
-o-animation-fill-mode:both;
animation-fill-mode:both;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
-ms-animation-duration:1s;
-o-animation-duration:1s;
animation-duration:1s;}
.animated.hinge
{
-webkit-animation-duration:2s;
-moz-animation-duration:2s;
-ms-animation-duration:2s;
-o-animation-duration:2s;
animation-duration:2s;
}
@-webkit-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-webkit-transform: translateY(0);}
40% {-webkit-transform: translateY(-30px);}
60% {-webkit-transform: translateY(-15px);}
}
@-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-moz-transform: translateY(0);}
40% {-moz-transform: translateY(-30px);}
60% {-moz-transform: translateY(-15px);}
}
@-o-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-o-transform: translateY(0);}
40% {-o-transform: translateY(-30px);}
60% {-o-transform: translateY(-15px);}
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
40% {transform: translateY(-30px);}
60% {transform: translateY(-15px);}
}
#Home:hover {
-webkit-animation-name: bounce;
-moz-animation-name: bounce;
-o-animation-name: bounce;
animation-name: bounce;
}
是为动画
嗨那里,道歉的慢回复。 我已经实现了给定的代码,但是我试过所有显示整个背景图片,它的动画效果很好,但高度和宽度值不会改变? – WibblyWobbly
你有没有尝试过使用'background-size'属性?第一个值是宽度,第二个是高度。使用百分比将其设置为容器大小的百分比。我有点困惑于你的问题:你是说你想动画的大小(所以它变得更大或更小),或者是整个时间错误的大小?如果你做一个新的小提琴,我会看看它,并试图帮助。 – raphaelvalerio