我很乐意帮您翻译。以下是您需要翻译的内容:
我发现了一个非常好的 SVG 按钮动画示例,但按钮的大小是静态的 - 320px x 60px。我想让按钮具有响应性 - 它是 SVG 矩形,但我很难实现。
HTML:
<div class="svg-wrapper">
<svg class="svg-responsive" viewBox="0 0 320 60" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
<rect class="shape" width="100%" height="100%"/>
</svg>
<div class="text">HOVER</div>
</div>
CSS:
.svg-wrapper {
border: 1px solid red;
position: relative;
height: 0;
padding-top: 16.6%;
}
svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.shape {
width: 100%;
height: 100%;
fill: salmon;
stroke-dasharray: 140 540;
stroke-dashoffset: -474;
stroke-width: 8px;
stroke: #19f6e8;
}
.text {
color: #fff;
font-family: "Roboto Condensed";
font-size: 22px;
letter-spacing: 8px;
line-height: 32px;
position: relative;
top: -48px;
}
@keyframes draw {
0% {
stroke-dasharray: 140 540;
stroke-dashoffset: -474;
stroke-width: 8px;
}
100% {
stroke-dasharray: 760;
stroke-dashoffset: 0;
stroke-width: 2px;
}
}
.svg-wrapper:hover .shape {
-webkit-animation: 0.5s draw linear forwards;
animation: 0.5s draw linear forwards;
}
https://codepen.io/anon/pen/dePNLG
我已经阅读了一篇关于这个问题的教程,并且按照其中所有步骤为内联SVG进行操作,但是我认为我还是遗漏了某些细节。你能帮我让那个SVG矩形具有响应性吗?