2016-04-23 36 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)}

谢谢