I am updating the div on the page using jQuery mobile to play some animations.
Animations also play sound using document.createElement('audio');
My problem is that when I refresh the page to another animation, the old sound continues to play.
Sorry, this is my first question, and if it seems to me that I am not formulating it correctly, I apologize.
Here is my code ..
Here is the animation code loaded in the #animation div
<!DOCTYPE HTML> <html> <head> <style> body { margin: 0px; padding: 0px; } </style> </head> <body> <div id="container"></div> <script src="scripts/kinetic-v4.3.2.min.js"></script> <script src="scripts/jquery-1.9.1.js"></script> <script> var stage = new Kinetic.Stage({ container: 'container', width: 578, height: 400 }); var babyLayer = new Kinetic.Layer(); var backLayer = new Kinetic.Layer(); var imageObj = new Image(); var backObj = new Image(); imageObj.onload = function() { var baby = new Kinetic.Image({ x: stage.getWidth() / 2 -100 , y: stage.getHeight() / 2 -100, image: imageObj, width: 200, height: 200, opacity: 0.0 }); var background = new Kinetic.Image({ x: 0, y: 0, image: backObj, width: 578, height: 400, opacity: 0.0 }); </script>
Here is the code for the main page. It gets the name of the animation page file to load into #animation from the array when the next button is clicked.
<div id="nav" data-role="content" style="width: 600px; margin: 0 auto; text-align: center; position: relative; top:450px"> <a href="#animation" data-role="button" data-inline="true" id ="back">Back</a> <a href="#animation" data-role="button" data-inline="true" data-theme="b" id="next">Next</a> <script> var count=0; var link_array = ['baby', 'bed', 'book', 'cat', 'chair', 'daddy', 'dog', 'mummy', 'shoe', 'teddy']; $("#next").click(function(e) { if(count!==9) { $('audio').stop(); count+=1; } $('#animation1wl').load('../Animations/' + link_array[count] + '.html'); $('#animation1wl').trigger('create'); }); $("#back").click(function(e) { if(count !==0) { count-=1; } $('#animation1wl').load('../Animations/' + link_array[count] + '.html'); $('#animation1wl').trigger('create'); }); </script> </div> <div id="animation" data-role="content" style="width: 600px; margin: 0 auto; text-align: left">Problem Loading Resource LNW</div>
When I press the buttons forward or backward, I want the sound from the previous animation to load into #animation to stop playback.
Here is the code displayed inside #animation
<div id="animation1wl" data-role="content" style="width: 600px; margin: 0 auto; text-align: left" class="ui-content" role="main"> <style> body { margin: 0px; padding: 0px; } </style> <div id="container"><div style="position: relative; display: inline-block; width: 578px; height: 400px;" class="kineticjs-content"><canvas width="578" style="width: 578px; height: 400px; position: absolute;" height="400"></canvas><canvas width="578" style="width: 578px; height: 400px; position: absolute;" height="400"></canvas></div></div> <script src="scripts/kinetic-v4.3.2.min.js"></script> <script src="scripts/jquery-1.9.1.js"></script> <script> var stage = new Kinetic.Stage({ container: 'container', width: 578, height: 400 }); var babyLayer = new Kinetic.Layer(); var backLayer = new Kinetic.Layer(); var imageObj = new Image(); var backObj = new Image(); imageObj.onload = function() { var baby = new Kinetic.Image({ x: stage.getWidth() / 2 -100 , y: stage.getHeight() / 2 -100, image: imageObj, width: 200, height: 200, opacity: 0.0 }); var background = new Kinetic.Image({ x: 0, y: 0, image: backObj, width: 578, height: 400, opacity: 0.0 }); </script> </div>
Any help would be great.
Thank you very much.