[JAVASCRIPT] Effetto sonoro su onmouseover
Utilizzo il seguente script per il caricamento dei pulsanti del menu, dai nomi "pulsante_bX.gif", "pulsante_bX_over.gif", dove la X va da 1 a 7 (sette pulsanti) e quelli con estensione "_over" vengono visualizzati al passaggio del mouse per creare qualcosa di interattivo:
Codice HTML:
var clicked=""
var gtype=".gif"
var selstate="_over"
if (typeof(loc)=="undefined" || loc==""){
var loc=""
if (document.body&&document.body.innerHTML){
var tt = document.body.innerHTML.toLowerCase();
var last = tt.indexOf("pulsante.js\"");
if (last>0){
var first = tt.lastIndexOf("\"", last);
if (first>0 && first<last) loc = document.body.innerHTML.substr(first+1,last-first-1);
}
}
}
document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
document.write("<td><img src=\""+loc+"pulsante_top.gif\" alt=\"\" width=\"133\" height=\"23\"></td>");
tr(false);
writeButton(loc+"","../home.htm","pulsante_b1",133,29,"","",0);
writeButton("","http://217.133.9.70:8080/","pulsante_b2",133,29,"","",0);
writeButton(loc+"","../galleria.htm","pulsante_b3",133,29,"","",0);
writeButton(loc+"","../guestbook.htm","pulsante_b4",133,29,"","",0);
writeButton(loc+"","../chat.htm","pulsante_b5",133,29,"","",0);
writeButton(loc+"","../contatti.htm","pulsante_b6",133,29,"","",0);
writeButton(loc+"","../links.htm","pulsante_b7",133,29,"","",0);
tr(true);
document.write("<td><img src=\""+loc+"pulsante_bottom.gif\" alt=\"\" width=\"133\" height=\"23\"></td>");
document.write("</tr></table>")
loc="";
function tr(b){if (b) document.write("<tr>");else document.write("</tr>");}
function turn_over(name) {
if (document.images != null && clicked != name) {
document[name].src = document[name+"_over"].src;
}
}
function turn_off(name) {
if (document.images != null && clicked != name) {
document[name].src = document[name+"_off"].src;
}
}
function reg(gname,name)
{
if (document.images)
{
document[name+"_off"] = new Image();
document[name+"_off"].src = loc+gname+gtype;
document[name+"_over"] = new Image();
document[name+"_over"].src = loc+gname+"_over"+gtype;
}
}
function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}
function writeButton(urld, url, name, w, h, alt, target, hsp)
{
gname = name;
while(typeof(document[name])!="undefined") name += "x";
reg(gname, name);
tr(true);
document.write("<td>");
if (alt != "") alt = " alt=\"" + alt + "\"";
if (target != "") target = " target=\"" + target + "\"";
if (w > 0) w = " width=\""+w+"\""; else w = "";
if (h > 0) h = " height=\""+h+"\""; else h = "";
if (url != "") url = " href=\"" + urld + url + "\"";
document.write("<a " + url + evs(name) + target + ">");
if (hsp == -1) hsp =" align=\"right\"";
else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";
else hsp = "";
document.write("<img src=\""+loc+gname+gtype+"\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" /></a></td>");
tr(false);
}
Utilizzo il comando "onmouseover" per cambiare immagine del pulsante quando viene posizionato il puntatore sopra di esso.
Vorrei fare in modo che venisse caricato ed eseguito anche un piccolo effetto sonoro al passaggio del mouse ed in caso di click sul pulsante. Ho fatto alcune prove tramite la funzione document.write ma senza successo.
Chiedo ora a voi, a qualcuno di buona volontà, dove dovrei inserire il codice idoneo per ottenere quello che ho indicato.
Grasssssie!
FrankyFive