2016-04-23 37 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分開嗎? 應該在mouseout函數中的行如下:thissound.play().animate({volume: 0}, 1000)}

謝謝