링크에 마우스 올리면 소리나게 하기
페이지 정보
작성자본문
<head>
<title>링크에 mouseover하게되면 소리출력</title>
</head>
<body>
<bgsound src="#" id="soundeffect" loop=1 autostart="true" />
<script type="text/javascript">
var soundfile="./err.wav"   //사운드파일경로
function playsound(soundfile){
    if (document.all && document.getElementById){
        document.getElementById("soundeffect").src="" 
        document.getElementById("soundeffect").src=soundfile
    }
}
function bindsound(tag, soundfile, masterElement){
    if (!window.event) return
    var source=event.srcElement
    while (source!=masterElement && source.tagName!="HTML"){
    if (source.tagName==tag.toUpperCase()){
        playsound(soundfile)
    break
    }
    source=source.parentElement
    }
}
</script>
<B>레이어영역 DIV에 있을때</B><br>
<div id="coolmenu" onMouseover="bindsound('A', soundfile, this)">
    <a href="">menu #1</a><br>
    <a href="">menu #2</a><br>
    <a href="">menu #3</a><br>
</div>
<p>
<B>링크에 바로 사운드 연결 1 (소스에 설정된 사운드 파일 재생)</B></br>
<a href="#" onMouseover="playsound('./ding.wav')">Example 1</a><p>
<B>링크에 바로 사운드 연결 2 (링크에 다른 사운드 파일 재생)</B></br>
<a href="#" onMouseover="playsound('./err.wav')">Example 2</a> 
본 소스를 실행하기 위해서는 ding.wav, err.wav에 해당하는 테스트용 사운드 파일이 있어야한다.
댓글목록
등록된 댓글이 없습니다.
