2010-02-18 3 views
1

사이트의 메뉴 버튼에 대한 onmouseover 사운드 효과에 다음 스크립트를 사용하고 있습니다.Firefox의 Onmouseover 사운드

<script LANGUAGE="JavaScript"><!-- 


var aySound = new Array(); 

aySound[0] = "s.mp3"; 

document.write('<BGSOUND ID="auIEContainer">') 
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0; 
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0; 
ver4 = IE||NS? 1:0; 
onload=auPreload; 

function auPreload() { 
if (!ver4) return; 
if (NS) auEmb = new Layer(0,window); 
else { 
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>"; 
document.body.insertAdjacentHTML("BeforeEnd",Str); 
} 
var Str = ''; 
for (i=0;i<aySound.length;i++) 
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>" 
if (IE) auEmb.innerHTML = Str; 
else { 
auEmb.document.open(); 
auEmb.document.write(Str); 
auEmb.document.close(); 
} 
auCon = IE? document.all.auIEContainer:auEmb; 
auCon.control = auCtrl; 
} 
function auCtrl(whSound,play) { 
if (IE) this.src = play? aySound[whSound]:''; 
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()")) 
} 
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); } 
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); } 
//--> 
</script> 

IE에서는 제대로 작동하지만 Firefox에서는 작동하지 않습니다.

플래시를 사용하지 않고 IE와 Firefox에서 동일한 onmouseover 사운드 효과를 얻는 방법이 있는지 아는 사람이 있습니까?

감사

답변

0

웹 사이트에 소리의 유일한 방법은 페이스 북이 들어오는 IM에 사용하는 어떤 플래시 또는 중 하나를 사용하는 것입니다,하지만 너무 재생 애플 퀵타임이 필요합니다.

0

플래시를 사용하지 않고 IE와 Firefox 모두에서 동일한 onmouseover 사운드 효과를 얻는 방법이 있는지 아는 사람이 있습니까?

글쎄 브라우저 간 브라우저 onmouseover 동작을 정상화하는 JavaScript 라이브러리를 사용할 수 있습니다. 또는, 정말로 원하지 않는다면 - 모든 브라우저를 지원하기 위해 많은 해킹이 필요한 일반 JavaScript로 가능해야합니다. 너의 선택.

gist 243946에 게시 된

는 여기에 jQuery를 조각 당신이 원하는 것을 정확히 할입니다 : 물론

var $sound = $('<div id="sound" />').appendTo('body'); 
$('#special-links-that-play-annoying-sounds-when-hovered a').hover(function() { 
$sound.html('<embed src="foo.mp3" hidden="true" autostart="true" loop="false">'); 
}, function() { 
// We could empty the innerHTML of $sound here, but that would only slow things down. 
}); 

이, 이것은뿐만 아니라 (jQuery를하지 않고) 보통 오래된 자바 스크립트로 작성 될 수있다.