Results 1 to 2 of 2

Thread: help toggling sound with on/off img buttons

  1. #1
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default help toggling sound with on/off img buttons

    the below code is working, i just need help with the music. when the button is clicked, i want it to play loop.mp3 and when it is clicked again I want it to stop. personally, i always have trouble with embedding sound with javascript, especially adding it to other functions going on. sorry for the newbie question, but thanks in advance.

    Code:
    <script language="javascript"> 
    function toggle() {
    	var ele = document.getElementById("toggleText");
    	var text = document.getElementById("displayText");
    	if(ele.style.display == "block") {
        		ele.style.display = "none";
    		text.innerHTML = "<img src='paused.gif' border='0'>";
      	}
    	else {
    		ele.style.display = "block";
    		text.innerHTML = "<img src='system/playing.gif' border='0'>";
    	}
    } 
    </script>
     
    <a id="displayText" href="javascript:toggle();"><img src="paused.gif" border='0'></a>
    <div id="toggleText" style="display: none"><h1>sound should play now</h1></div>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Flash is a better choice for this. But if you want to use HTML and javascript, see:

    http://loisimages.com/john/music/music_adv_dd.htm

    Use your browser's 'view source' to get the code.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •