I have problem in arrow animation on the hover of the Anchor Tag. While I am hover on the first Anchor tag animation working properly and changing style with the JavaScript. But problem is the while I am using multiple Anchor tag it's only work perfect in the first one and while in another Anchor tag java script not working properly. I try many solution but not fix the issue. Please give me suggestion on it. I wrote my code below. Thank You.
var timeout;
var element = document.getElementById("btn");
element.onmouseover = function (e) {
timeout = setTimeout(function () {
document.getElementById("ab").style.display = "none";
document.getElementById("xy").style.display = "block";
}, 700)
};
element.onmouseout = function (e) {
if (timeout) {
document.getElementById("ab").style.display = "block";
document.getElementById("xy").style.display = "none";
clearTimeout(timeout);
}
}
.main-arrow {
transition-delay: 0.2s;
transform-box: fill-box;
transform-origin: center;
transition-duration: 0.5s;
}
.sec-arrow {
transform-box: fill-box;
transform-origin: center;
transition-duration: 0.5s;
}
.hori,
.sec-hori {
transform-box: fill-box;
transform-origin: center;
transition-duration: 0.5s;
}
.btn:hover .arrow {
animation-name: mainrotatingarrow;
animation-duration: 0.2s;
animation-fill-mode: forwards;
}
.btn:hover .hori {
animation-name: hori;
animation-duration: 0.2s;
animation-fill-mode: forwards;
}
.btn:hover .sec-hori {
animation-name: sechori;
animation-duration: 0.2s;
animation-fill-mode: forwards;
animation-delay: 0.7s;
}
.btn:hover .sec-arrow {
animation-name: secondrotatingarrow;
animation-duration: 0.2s;
animation-fill-mode: forwards;
animation-delay: 0.7s;
}
.btn:hover .main-arrow {
animation-name: rotatingarrow;
animation-duration: 0.5s;
animation-fill-mode: forwards;
animation-delay: 0.2s;
transition-duration: 0.5s;
}
#xy {
display: none;
}
/* main */
@keyframes mainrotatingarrow {
0% {
d: path("M10.5 0.999999L16.5 7L10.5 13");
}
30% {
d: path("M10.5 0.999999L14 7L10.5 13");
}
65% {
d: path("M10.5 0.999999L12 7L10.5 13");
}
100% {
d: path("M10.5 0.999999L10.5 7L10.5 13");
}
}
/* second */
@keyframes secondrotatingarrow {
0% {
d: path("M10.5 0.999999L10.5 7L10.5 13");
}
30% {
d: path("M10.5 0.999999L12 7L10.5 13");
}
65% {
d: path("M10.5 0.999999L14 7L10.5 13");
}
100% {
d: path("M10.5 0.999999L16.5 7L10.5 13");
}
}
@keyframes hori {
0% {
d: path("M16 7L0 7");
}
100% {
d: path("M16 7L5 7");
}
}
@keyframes sechori {
0% {
d: path("M16 7L5 7");
}
100% {
d: path("M16 7L0 7");
}
}
@keyframes rotatingarrow {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(90deg);
}
}
<a href="#" class="btn" id="btn">
<span> View More</span>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="14" viewBox="0 0 18 14" fill="none" id="svg-ax">
<g class="main-arrow" id="ab">
<path class="hori" d="M16 7L0 7" stroke="#00AEEF" />
<path class="arrow" d="M10.5 0.999999L16.5 7L10.5 13" stroke="#00AEEF" />
</g>
<g class="second-arrow" id="xy">
<path class="sec-hori" d="M16 7L5 7" stroke="#00AEEF" />
<path class="sec-arrow" d="M10.5 0.999999L10.5 7L10.5 13" stroke="#00AEEF" />
</g>
</svg>
</a>
<a href="#" class="btn" id="btn">
<span> View More</span>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="14" viewBox="0 0 18 14" fill="none" id="svg-ax">
<g class="main-arrow" id="ab">
<path class="hori" d="M16 7L0 7" stroke="#00AEEF" />
<path class="arrow" d="M10.5 0.999999L16.5 7L10.5 13" stroke="#00AEEF" />
</g>
<g class="second-arrow" id="xy">
<path class="sec-hori" d="M16 7L5 7" stroke="#00AEEF" />
<path class="sec-arrow" d="M10.5 0.999999L10.5 7L10.5 13" stroke="#00AEEF" />
</g>
</svg>
</a>
<a href="#" class="btn" id="btn">
<span> View More</span>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="14" viewBox="0 0 18 14" fill="none" id="svg-ax">
<g class="main-arrow" id="ab">
<path class="hori" d="M16 7L0 7" stroke="#00AEEF" />
<path class="arrow" d="M10.5 0.999999L16.5 7L10.5 13" stroke="#00AEEF" />
</g>
<g class="second-arrow" id="xy">
<path class="sec-hori" d="M16 7L5 7" stroke="#00AEEF" />
<path class="sec-arrow" d="M10.5 0.999999L10.5 7L10.5 13" stroke="#00AEEF" />
</g>
</svg>
</a>