我正在使用CSS过渡和变换来缩放SVG中的circle元素的大小。但是,当我的鼠标离开该元素时,似乎出现了抽动现象。
<svg viewBox="-5 -5 50 50">
<circle cx="20" cy="20" r="20" />
<path d="M20,31 C15.4189994,27.2225585 12.5023327,24.2225585 11.25,22 C10.2743515,20.6156479 10,19.6181623 10,18.1428571 C10,15.5113854 12.4883456,13 15,13 C17.3176009,13 18.9621484,13.8491346 20,15.5714286 C21.0382977,13.8491346 22.6828452,13 25,13 C27.5116544,13 30,15.5113854 30,18.1428571 C30,19.6181623 29.7256485,20.6156479 28.75,22 C27.497816,24.2225585 24.5811493,27.2225585 20,31 Z" />
CSS:
circle {
fill: #EEE;
-webkit-transition: -webkit-transform .1s ease-in-out;
-moz-transition: -moz-transform .1s ease-in-out;
}
path {
fill: #CCC;
}
svg:hover circle {
transform: scale(1.15);
-ms-transform: scale(1.15);
-webkit-transform: scale(1.15);
transform-origin: center center;
-webkit-transform-origin: center center;
-ms-transform-origin: center center;
}
答案 0 :(得分:2)
将transform-origin
属性移至circle
的一般规则内,这样就不必处理其放置仅在:hover
:
circle {
fill: #EEE;
-webkit-transition: -webkit-transform .1s ease-in-out;
-moz-transition: -moz-transform .1s ease-in-out;
transform-origin: center center;
-webkit-transform-origin: center center;
-ms-transform-origin: center center;
}
path {
fill: #CCC;
}
svg:hover circle {
transform: scale(1.15);
-ms-transform: scale(1.15);
-webkit-transform: scale(1.15);
}
<svg viewBox="-5 -5 50 50">
<circle cx="20" cy="20" r="20" />
<path d="M20,31 C15.4189994,27.2225585 12.5023327,24.2225585 11.25,22 C10.2743515,20.6156479 10,19.6181623 10,18.1428571 C10,15.5113854 12.4883456,13 15,13 C17.3176009,13 18.9621484,13.8491346 20,15.5714286 C21.0382977,13.8491346 22.6828452,13 25,13 C27.5116544,13 30,15.5113854 30,18.1428571 C30,19.6181623 29.7256485,20.6156479 28.75,22 C27.497816,24.2225585 24.5811493,27.2225585 20,31 Z" />
</svg>