2016-04-23 17 views
2

オブジェクトにホバリングしたときにサウンドをアクティブにするが、シンプルなフェードインとフェードアウトエフェクトを追加したい(ホバーイン時にフェードインし、ホバーイン時にフェードアウトする)次のコードがあります。ヒントにはうれしいでしょう。ホバー機能でフェードインとフェードアウト機能を追加する方法は?

function PlaySound(soundobj) { 
var thissound=document.getElementById(soundobj); 
thissound.play()} 

function StopSound(soundobj) { 
var thissound=document.getElementById(soundobj); 
thissound.pause(); 
thissound.currentTime = 0;} 

答えて

0

ありがとうございます。

まだ動作していないようです。私はいくつかの広告が最初にこれを試してみました訂正:

function PlaySound(soundobj) { 
var thissound=document.getElementById(soundobj); 

/* putting sound on hold and setting volume to 0 */ 
thissound.pause().prop("volume", 0); 

/* on mouse hover event, play sound and fade in the volume in 1s */ 
thissound.mouseover(function() { 
    thissound.play().animate({volume: 1}, 1000); 
});} 

function StopSound(soundobj) { 
var thissound=document.getElementById(soundobj); 

/* on mouse out event, fade out the volume in 1s */ 
thissound.mouseout(function() { 
    thissound.animate({volume: 0}, 1000)} 
}); 
thissound.pause(); 
thissound.currentTime = 0; 
} 

私の質問は次のようになり、 は初期音量設定が関数PlaySoundから分離されなければなりませんか? マウス出力関数の行は、次のようになります。thissound.play().animate({volume: 0}, 1000)}

ありがとう

関連する問題