【发布时间】:2015-06-24 18:06:05
【问题描述】:
我正在编写鼠标悬停时触发的 CSS3 效果;这种效果只是动画一个内部 div 无限缩放它。
一切都很好,但是当我将鼠标移开时,div 突然恢复到原来的大小。我想添加一个平滑的效果来缩小 div。
我已经检查了这篇文章的建议: Make CSS Hover state remain after "unhovering" 不幸的是,发布的代码不起作用:( 在我看来,我的问题可能与规模效应的“无限”循环有关。
我想要达到的目标是鼠标移出时图像可以顺利恢复到原始大小。
这是代码:https://jsfiddle.net/9dtqpsLa/1/
CSS
@keyframes imageZoom{
0% { transform: scale(1); }
50% { transform: scale(1.24); }
100% { transform: scale(1);}
}
@-moz-keyframes imageZoom{
0% { -moz-transform: scale(1);}
50% { -moz-transform: scale(1.24); }
100% { -moz-transform: scale(1); }
}
@-webkit-keyframes imageZoom{
0% { -webkit-transform: scale(1); }
50% {-webkit-transform: scale(1.24); }
100% { -webkit-transform: scale(1); }
}
@-ms-keyframes imageZoom{
0% { -ms-transform: scale(1); }
50% { -ms-transform: scale(1.24); }
100% { -ms-transform: scale(1); }
}
.article:hover .imageWrapper {
animation: imageZoom linear 10s;
animation-iteration-count: infinite;
-webkit-animation: imageZoom linear 10s;
-webkit-animation-iteration-count: infinite;
-moz-animation: imageZoom linear 10s;
-moz-animation-iteration-count: infinite;
-ms-animation: imageZoom linear 10s;
-ms-animation-iteration-count: infinite;
transform-origin: 50% 80%;
}
.article {
background-color: #e6e6e6;
overflow: hidden;
width: 300px;
height: 300px;
}
.imageWrapper {
background-image: url('http://www.astutegraphics.com/images/blog/tutorials/widthscribe_patterns_18_mar_2013/floral-seamless-pattern.png');
width: 300px;
height: 300px;
}
HTML
<div class="article">
<div class="imageWrapper">
</div>
</div>
拜托,你能帮帮我吗?
非常感谢
【问题讨论】:
-
发生这种情况是因为您的动画设置为在悬停
.article时播放。如果您只想在悬停时开始动画,然后让它永久播放,则需要使用 JavaScript。