您可以通过使用 Chrome DevTools 或参考站点中的其他类似工具来了解如何执行此操作。
<div class='button'>
<button>Click Me</button>
<svg preserveAspectRatio="none">
<path fill="none" d="..." />
</svg>
</div>
Run Code Online (Sandbox Code Playgroud)
.button {
position: relative;
display: inline-block;
cursor: pointer;
}
.button button {
padding: 8px 16px;
border: none;
background: none;
outline: none;
}
.button svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.button path {
stroke: #db3157;
stroke-width: 8px;
stroke-dasharray: 0 1500;
}
.button:hover path {
animation: draw 1s forwards;
}
@keyframes draw {
from {
stroke-dasharray: 0 1500;
}
to {
stroke-dasharray: 1500 1500;
}
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle上的示例