I have created an application that mimics the functionality of an equalizer by displaying changes in audio frequencies.
https://i.sstatic.net/W7Fzi.png
Issues with animation arise when you click the "Start" button again.
The animation resets and begins from the start.
This can be prevented by implementing protection against repeated clicks while the animation is active
restart ="whenNotactive"
However, this solution only partially addresses the problem.
I attempted to trigger a begin = "start.click"
event on the "Start" button and
an end = "pause.click"
event on the "Pause" button.
Below is my code:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%" height="100%" viewBox="0 0 400 150" preserveAspectRatio="xMinYMin meet" >
<defs>
<!-- Mask for forming the display of a part of the active line (with stroke = "white") -->
<mask id="msk">
<rect width="100%" height="100%" fill="black" />
<rect x="15" y="0" width="60" height="160" fill="white" stroke="white" />
</mask>
</defs>
<!-- Black background -->
<rect width="22%" height="100%" fill="black" />
<!-- Colored line markers to show equalizer frequency levels -->
<polyline points="10,0 10,139" stroke="#4C4C50" />
<polyline points="80,0 80,139" stroke="#4C4C50" />
<polyline id="grey" points="20,0 20,139" stroke="#2A2A2C" />
<use xlink:href="#grey" x="10" />
<use xlink:href="#grey" x="20" />
<use xlink:href="#grey" x="30" />
<use xlink:href="#grey" x="40" />
<use xlink:href="#grey" x="50" />
<polyline points="15,2 74,2" stroke-width="2" stroke="#2A2A2C" />
<!-- Code continues -->
However, this approach does not achieve the desired outcome. The animation restarts from the beginning when you press the Start
button.
I am seeking a solution where pressing the Pause
button stops the animation, and subsequently pressing the Start
button resumes the animation from where it was paused.
Question:
How can I make the animation resume from where it left off when the Start
button is pressed again?
It seems like achieving this purely in SVG may not be feasible. Therefore, CSS and JavaScript solutions would be greatly beneficial.