tonybabb
07-08-2015, 11:58 AM
Beverly very kindly helped me create a js script that played a sound file from a list and changed the play/pause icon. This works perfectly and the thread can be seen here http://www.dynamicdrive.com/forums/showthread.php?77798-Customizing-controls-for-the-lt-audio-gt-tag&p=310353&highlight=#post310353 .
I have a small problem that I’ve been unable to fix. Some of the song titles are long and extend over two lines, when I click the play/pause icon the 2nd line of the title appears below the icon and not to the right of the icon. The effect can be seen here www.innocente.us/discography.php (http://www.innocente.us/discography.php)when you click on the play icon beside the song titles that extends over two lines the second line shows below the pause icon.
I think the problem is that when the play icon is clicked it is replaced by the pause icon but the attribute class=”fltlft” is removed and I can’t figure out how to retain it – I tried adding it to the variables playicon and pauseicon and it didn’t work - it fixed the alignment problem but when I clicked the pause icon the sound did not pause. Here's what I tried:
var playIcon = '<img class=”fltlft” src="images/play.png">';
var pauseIcon = '<img class=”fltlft” src="images/pause.png">';
Here’s a sample html (using debugger) showing the play icon before being clicked:
<a href="#">
<img class="fltlft" src="images/play.png"/>
And here’s the html (using debugger)after the play icon is clicked
<a href="#">
<img src="images/pause.png"/>
Notice that the class=”fltlft” is missing.
Here’s the script that swaps the play/ pause icon - without my changes above.
<script>
var ctrl = document.getElementById('audio').getElementsByTagName('a');
for(var i = 0; i < ctrl.length; i++){
ctrl[i].onclick = function(){
var audio = this.nextSibling;
while (audio.nodeType != 1){ audio = audio.nextSibling; }
var playIcon = '<img src="images/play.png">';
var pauseIcon = '<img src="images/pause.png">';
var pause = this.innerHTML === pauseIcon;
this.innerHTML = pause ? playIcon : pauseIcon;
var method = pause ? 'pause' : 'play';
audio[method]();
return false;
}
}
</script>
Thanks for any assistance you can provide.
Tony
I have a small problem that I’ve been unable to fix. Some of the song titles are long and extend over two lines, when I click the play/pause icon the 2nd line of the title appears below the icon and not to the right of the icon. The effect can be seen here www.innocente.us/discography.php (http://www.innocente.us/discography.php)when you click on the play icon beside the song titles that extends over two lines the second line shows below the pause icon.
I think the problem is that when the play icon is clicked it is replaced by the pause icon but the attribute class=”fltlft” is removed and I can’t figure out how to retain it – I tried adding it to the variables playicon and pauseicon and it didn’t work - it fixed the alignment problem but when I clicked the pause icon the sound did not pause. Here's what I tried:
var playIcon = '<img class=”fltlft” src="images/play.png">';
var pauseIcon = '<img class=”fltlft” src="images/pause.png">';
Here’s a sample html (using debugger) showing the play icon before being clicked:
<a href="#">
<img class="fltlft" src="images/play.png"/>
And here’s the html (using debugger)after the play icon is clicked
<a href="#">
<img src="images/pause.png"/>
Notice that the class=”fltlft” is missing.
Here’s the script that swaps the play/ pause icon - without my changes above.
<script>
var ctrl = document.getElementById('audio').getElementsByTagName('a');
for(var i = 0; i < ctrl.length; i++){
ctrl[i].onclick = function(){
var audio = this.nextSibling;
while (audio.nodeType != 1){ audio = audio.nextSibling; }
var playIcon = '<img src="images/play.png">';
var pauseIcon = '<img src="images/pause.png">';
var pause = this.innerHTML === pauseIcon;
this.innerHTML = pause ? playIcon : pauseIcon;
var method = pause ? 'pause' : 'play';
audio[method]();
return false;
}
}
</script>
Thanks for any assistance you can provide.
Tony