Стрелка нарисована в виде двух линий, поэтому анимацию невозможно создать, изменив атрибуты stroke-dasharray
и stroke-dashoffset
Попробуйте анимировать атрибут d
path
. Для этого вам понадобится начальная path
короткой стрелки и последний патч длинной стрелки.
Чтобы анимация работала правильно, необходимо, чтобы количество узловых точек и их тип были одинаковыми в обоих патчах
Чтобы выполнить эти условия, вам необходимо загрузить первый патч в векторный редактор и растяните стрелку, перетаскивая узлы точек
Скопируйте патч длинной стрелки в другой файл SVG. И напишите формулу анимации для атрибута d
<animate id="_animate"
attributeName="d"
begin="indefinite"
dur="2s"
repeatCount="3"
values="
path-short-arrow;
path-long-arrow"
fill="freeze"
Ниже приведен полный код
var svg = document.getElementById('block');
svg.addEventListener("mouseover",() =>{
_animate.beginElement();
})
#block {
position: relative;
width:40ww;
height:auto;
max-width:450;
background-color: #1D4976;
}
#arrow-normal {
padding:1.5em;
}
#svg1 {
position: absolute;
bottom:30px;
right:50px;
}
#path {
fill:white;
stroke-width:2;
stroke:white;
}
.text1 {
padding-top:14px;
display:inline-block;
font-size:26px;
color:white;
}
.text2 {
padding-top:60px;
display:inline-block;
font-size:22px;
color:white;
}
<div id="block">
<div id="arrow-normal">
<span class="text1"> Fusce ultricies maximus ante vitae imperdiet. Proin magna orci pretium nec </span>
<span class="text2"> Nullam ornare turpis quis orci </span>
<svg id="svg1" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="50" height="16" viewBox="0 0 50 16" version="1.1" fill="none">
<path id="path" d="m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z" >
<animate id="_animate"
attributeName="d"
begin="indefinite"
dur="2s"
repeatCount="2"
restart="whenNotActive"
values="
m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z;
m42.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H46.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z;
m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z"
fill="freeze" />
</path>
</svg>
</div>
</div>
Опция со стрелкой из тире
var svg = document.getElementById('block');
svg.addEventListener("mouseover",() =>{
_animate.beginElement();
})
#block {
position: relative;
width:40ww;
height:auto;
max-width:450;
background-color: #1D4976;
}
#arrow-normal {
padding:1.5em;
}
#svg1 {
position: absolute;
bottom:30px;
right:50px;
stroke-dasharray:4 1;
}
#path {
fill:white;
stroke-width:2;
stroke:white;
}
.text1 {
padding-top:14px;
display:inline-block;
font-size:26px;
color:white;
}
.text2 {
padding-top:60px;
display:inline-block;
font-size:22px;
color:white;
}
<div id="block">
<div id="arrow-normal">
<span class="text1"> Fusce ultricies maximus ante vitae imperdiet. Proin magna orci pretium nec </span>
<span class="text2"> Nullam ornare turpis quis orci </span>
<svg id="svg1" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="50" height="16" viewBox="0 0 50 16" version="1.1" fill="none">
<path id="path" d="m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z" >
<animate id="_animate"
attributeName="d"
begin="indefinite"
dur="2s"
repeatCount="2"
restart="whenNotActive"
values="
m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z;
m42.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H46.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z;
m14.7 1.4c-0.3-0.3-0.7-0.3-1 0-0.3 0.3-0.3 0.7 0 1l5 5H2.1c-0.4 0-0.7 0.3-0.7 0.7 0 0.4 0.3 0.7 0.7 0.7H18.7l-5 5c-0.3 0.3-0.3 0.7 0 1 0.3 0.3 0.7 0.3 1 0l6.2-6.2c0.3-0.3 0.3-0.7 0-1z"
fill="freeze" />
</path>
</svg>
</div>
</div>