2012-04-30 5 views
1

J'utilise le script suivant affiché sur ce site: http://www.javascriptkit.com/script/...oundlink.shtmlCut & Paste HTML5 Mouseover/Click script effet sonore

Il fonctionne très bien, mais je veux étendre ce script et couper le son avec une case à cocher. Cette case à cocher a l'ID: son. Si cette case est cochée, je veux entendre les sons. Lorsqu'elle n'est pas cochée, aucun son ne doit être entendu.

C'est le code que j'ai actuellement la case à cocher: code:

function playSound() { 
    if (document.getElementById('sound').checked){ 
     -something needs to be added here to make it work?- 
    } 
} 

Quelqu'un a une idée de comment faire ce travail?

Un grand merci

Répondre

1

fonction muteIt (boîte) { si (clicksound) { clicksound.muted = box.checked vrai: faux; } si (mouseoversound) { mouseoversound.muted = case.checked? True: false; }}

+2

merci pour votre aide, cela fonctionne. – CryOfFaclon

0
<script> 

// Mouseover/ Click sound effect- by JavaScript Kit (www.javascriptkit.com) 
// Visit JavaScript Kit at http://www.javascriptkit.com/ for full source code 

//** Usage: Instantiate script by calling: var uniquevar=createsoundbite("soundfile1", "fallbackfile2", "fallebacksound3", etc) 
//** Call: uniquevar.playclip() to play sound 

var html5_audiotypes={ //define list of audio file extensions and their associated audio types. Add to it if your specified audio file isn't on this list: 
    "mp3": "audio/mpeg", 
    "mp4": "audio/mp4", 
"ogg": "audio/ogg", 
"wav": "audio/wav" 
} 

function createsoundbite(sound){ 
    var html5audio=document.createElement('audio') 
    if (html5audio.canPlayType){ //check support for HTML5 audio 
     for (var i=0; i<arguments.length; i++){ 
      var sourceel=document.createElement('source') 
      sourceel.setAttribute('src', arguments[i]) 
      if (arguments[i].match(/\.(\w+)$/i)) 
       sourceel.setAttribute('type', html5_audiotypes[RegExp.$1]) 
      html5audio.appendChild(sourceel) 
     } 
     html5audio.load() 
     html5audio.playclip=function(){ 
        if (document.getElementById('sound').checked){ 

       html5audio.pause() 
        html5audio.currentTime=0 
        html5audio.play() 

        } 
     } 
    return html5audio 
} 
else{ 
    return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}} 
} 
} 

//Initialize two sound clips with 1 fallback file each: 

var mouseoversound=createsoundbite("whistle.ogg", "whistle.mp3") 
var clicksound=createsoundbite("click.ogg", "click.mp3") 

</script> 

Alors, il va vérifier si la case est cochée. Si c'est le cas, alors ça va jouer. Si non, alors il ne jouera pas.