Condividi:        

onMouseOver + OnClick

Discussioni e opinioni costruttive sul mondo dell'informatica.
Per la soluzione di problemi specifici fare riferimento alle sezioni di assistenza!

Moderatori: aurelio37, Anthony47, axelrox

onMouseOver + OnClick

Postdi morwen » 05/11/04 20:47

Salve a tutti!!
Avrei bisogno di alcune delucidazioni su uno script che vorrei inserire in una pagina web.
Tenendo conto che entrambi i comandi in oggetto li saprei anche inserire (per fortuna internet mi aiuta, in questi casi :D ), c'è per caso uno script che permetta di inserirli entrambi?
Cioè...un suono al passaggio su un link e un altro cliccando sullo stesso link? :mmmh:

vi preeego *incrocia le dita*

Grazie comunque in anticipo!! ^^
morwen
Newbie
 
Post: 1
Iscritto il: 23/10/04 22:53

Sponsor
 

Postdi Triumph Of Steel » 06/11/04 01:44

per il suono trovi lo script qui

http://www.javascripter.net/faq/sound/play.htm
2° esempio
Avatar utente
Triumph Of Steel
Moderatore
 
Post: 7852
Iscritto il: 22/08/01 01:00

Postdi Dylan666 » 06/11/04 02:33

Scrip preso da qui opportunamente modificato

Codice: Seleziona tutto
<html>
<head>
<!--
This file retrieved from the JS-Examples archives
http://www.js-x.com
1000s of free ready to use scripts, tutorials, forums.
Author: JS-Examples - http://www.js-examples.com/
-->

<script>
var _s=0; /* just a counter - must start at 0 - do not change */
var Sounds = new Array();
    Sounds[_s++] = "tada.wav";  /* add any sound that will be pre-loaded */
    Sounds[_s++] = "rebin.wav"; /* add any sound that will be pre-loaded */

/* Frob below at own risk */
document.write('<BGSOUND ID="soundContainer_IE_DOM">');

/*
 * Browser-Sniffer
 */
var isIE4 = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? true:false;
var isNS4 = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? true:false;
var isDOM = document.getElementById?true:false;
var isOK = isIE4||isNS4||isDOM;

onload=PreLoadSounds; /* this will make the pre-loading occur - put in body tag onload="PreLoadMusic()" if you want */

function PreLoadSounds()
{
  if (!isOK)
    return;

  /*
   * This block creates a container-object to hold all the hidden pre-loaded sound objects.
   */
  if (isNS4)
    SoundDiv = new Layer(0,window);
  else
    document.body.insertAdjacentHTML("BeforeEnd","<DIV ID='SoundDiv' STYLE='position:absolute;'></DIV>");

  /*
   * This block writes all the sound objects into the container-object.
   */
  var Str = '';
  for (i=0;i<Sounds.length;i++)
    Str += "<EMBED SRC='"+Sounds[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"

  if(isDOM)
    document.getElementById("SoundDiv").innerHTML=Str;
  else if(isIE4)
    SoundDiv.innerHTML=Str;
  else
  {
    /* must be NS4 */
    SoundDiv.document.open();
    SoundDiv.document.write(Str);
    SoundDiv.document.close();
  }

  /*
   * This finds the object -- we want to set an access method to make it play or stop.
   */
  soundObject = null;
  if(isDOM)
    soundObject = document.getElementById('soundContainer_IE_DOM');
  else if(isIE4)
    soundObject = document.all.soundContainer_IE_DOM;
  else
    soundObject = SoundDiv;
  soundObject.control = auCtrl;
}

function auCtrl(SoundsArrayIndex,play)
{
  if (isIE4||isDOM)
    this.src = play? Sounds[SoundsArrayIndex]:'';
  else
    eval("this.document.embeds[SoundsArrayIndex]." + (play? "play()":"stop()"))
}

function playSound(SoundsArrayIndex) { if (window.soundObject) soundObject.control(SoundsArrayIndex,true); }
function stopSound(SoundsArrayIndex) { if (window.soundObject) soundObject.control(SoundsArrayIndex,false); }
</script>


</head>
<body>

<A HREF="#"
   onMouseOver="playSound(0)"
   onMouseOut="stopSound(0)">Move mouse over to play sound #1</A>
<BR>
<A HREF="#"
   onClick="playSound(1)">Click to play sound #2</A>

<BR><center><a href='http://www.js-x.com'>JS-X.com</a></center>
</body>
</html>


PS: mi pare che una volta provai pure io a dare un suono al click su un collegamento ma rinunciai notando che il WAV veniva suonato parzialmente perché interrotto dal caricamento della pagina linkata...
Avatar utente
Dylan666
Moderatore
 
Post: 39993
Iscritto il: 18/11/03 16:46


Torna a Discussioni


Topic correlati a "onMouseOver + OnClick":


Chi c’è in linea

Visitano il forum: Nessuno e 37 ospiti