I use a html5 CMS template in which I also want to integrate SVG animations. An audio file is linked to a SMIL animation. This could only be solved with javascript.
The problem arises when the audio SVG animation is stopped and started again. Both should go with one click, but it doesn't succeed, because I can't enter 2 times click in the javacript for the SMIL animation for both states, paused and unpaused.
How can I concatenate this both sources?: (You can see it on the site arteurope.de, you have to click on the button)
I need to put
svg.addEventListener("mouseout", function() {
svg.pauseAnimations();
into
svg.addEventListener("click", function() {
svg.pauseAnimations();
But then the animation doesn`t start, because the "click" of first function says: unpauseAnimation, and the second function says: pauseAnimation.
<script type="text/javascript">
(function () {var svg = document.getElementsByTagName('svg')[0],
audio = null;
svg.addEventListener('click', handler, false);
function handler() {
if (!audio) {
audio = new Audio('https://arteurope.de/files/Vergessen.mp3');
audio.play();
} else if (audio && audio.paused) {
audio.play();
} else {
audio.pause();
}
}
})();
</script>
<script type="text/javascript">
var svg = document.querySelector(".svg-gears");
svg.pauseAnimations();
svg.addEventListener("click", function() {
svg.unpauseAnimations();
});
svg.addEventListener("mouseout", function() {
svg.pauseAnimations();
});
</script>