I'm diving into the world of SVG animation using JavaScript. I have a scenario where there is a play button at the beginning, which, when clicked, triggers the music to start playing and should hide itself.
Here's a look at my HTML setup:
<audio>
<source src="song.mp3" type="audio/mp3" />
</audio>
<svg id="canvas" xmlns:html="http://www.w3.org/1999/xhtml">
<!-- Definitions -->
<defs>
<linearGradient id="white-grey" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:#F5F5F5;stop-opacity:1" />
<stop offset="100%" style="stop-color:#D9D9D9;stop-opacity:1" />
</linearGradient>
<linearGradient id="grey-white" x1="0%" y1="100%" x2="0%" y2="0%">
<stop offset="0%" style="stop-color:#F5F5F5;stop-opacity:1" />
<stop offset="100%" style="stop-color:#D9D9D9;stop-opacity:1" />
</linearGradient>
</defs>
<g id="play-button" onclick="start()">
<rect x="300" y="200" rx="20" ry="20" width="200" height="100"
fill="url(#white-grey)" stroke="#5E5E5E" stroke-width="2">
</rect>
<text x="361" y="259" fill="#5E5E5E" font-size="30">
PLAY
</text>
</g>
</svg>
Additionally, here's the JavaScript function included:
function start() {
try {
$('audio').currentTime=0;
}
catch(e) {}
$('audio').play();
$('#play-button').css({"visibility":"hidden"});
}
While the audio playback part works fine, I seem to be facing an issue with hiding the play button once it is clicked. Any suggestions on what might be causing this behavior?