我已在SVG的transition
属性上使用stroke-dashoffset
创建了以下径向擦拭:
此功能在IE11和MS Edge除外的所有主流浏览器中均能正常工作。我的项目需要同时支持这两种浏览器,CanIUse表示这两种浏览器均应支持我用来实现效果的这些声明。为什么IE11和MS Edge在忽略:hover
属性上的:focus
的情况下立即渲染transition
和stroke-dashoffset
上的蓝绿色环?
我的代码如下。请注意,background-image
不会显示,因为它未在代码段中链接。
.avatar {
position: relative;
display: block;
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 2px;
padding: 0.125rem;
border: 1px solid #c9c9c9;
border: 0.0625rem solid #c9c9c9;
border-radius: 100%;
}
.avatar--m {
width: 40px;
width: 2.5rem;
height: 40px;
height: 2.5rem;
}
.avatar__border {
position: absolute;
top: -1px;
top: -0.0625rem;
left: -1px;
left: -0.0625rem;
}
.avatar--m > .avatar__border {
width: 40px;
width: 2.5rem;
height: 40px;
height: 2.5rem;
}
.avatar__border__stroke {
-webkit-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
transform: rotate(-90deg);
stroke: #11a0ad;
stroke-width: 1;
fill: none;
-webkit-transition: stroke-dashoffset 500ms ease-in-out;
-o-transition: stroke-dashoffset 500ms ease-in-out;
transition: stroke-dashoffset 500ms ease-in-out;
}
.avatar--m .avatar__border__stroke {
-webkit-transform-origin: 20px 20px;
-ms-transform-origin: 20px 20px;
transform-origin: 20px 20px;
-webkit-transform-origin: 1.25rem 1.25rem;
-ms-transform-origin: 1.25rem 1.25rem;
transform-origin: 1.25rem 1.25rem;
stroke-dasharray: 125.6636;
stroke-dashoffset: 125.6636;
}
.avatar:hover .avatar__border__stroke {
stroke-dashoffset: 0;
}
.avatar__image {
width: 100%;
height: 100%;
border-radius: 100%;
}
.avatar__image--male-1 {
background: url(/static/media/avatar__image--male-1.8982bdbc.svg), -webkit-linear-gradient(45deg, rgba(17, 160, 173, 0.13), rgba(33, 208, 217, 0.13)), white;
background: url(/static/media/avatar__image--male-1.8982bdbc.svg), -o-linear-gradient(45deg, rgba(17, 160, 173, 0.13), rgba(33, 208, 217, 0.13)), white;
background: url(/static/media/avatar__image--male-1.8982bdbc.svg), linear-gradient(45deg, rgba(17, 160, 173, 0.13), rgba(33, 208, 217, 0.13)), white;
background-position: center bottom -1px, 0;
background-position: center bottom -0.0625rem, 0;
background-repeat: no-repeat, repeat;
background-size: auto 85%, cover;
}
.badge {
display: inline-block;
min-width: 8px;
min-width: 0.5rem;
height: 24px;
height: 1.5rem;
padding: 0 8px;
padding: 0 0.5rem;
border-radius: 12px;
border-radius: 0.75rem;
background-color: rgba(0, 0, 0, 0.21);
color: white;
line-height: 24px;
line-height: 1.5rem;
font-size: 11px;
font-size: 0.6875rem;
font-weight: 700;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.badge--error {
background-color: #ed4a4a;
}
.avatar--m > .badge {
position: absolute;
top: -8px;
top: -0.5rem;
left: 24px;
left: 1.5rem;
cursor: pointer;
}
<a class="avatar avatar--m avatar--error" href="https://www.example.com" title="Charlie Winchester">
<svg class="avatar__border" viewBox="0 0 40 40">
<circle class="avatar__border__stroke" cx="20" cy="20" r="19.5"></circle>
</svg>
<div class="avatar__image avatar__image--male-1"></div>
<span class="badge badge--error" unselectable="on">1k+</span>
</a>