如何在悬停功能上添加淡入和淡出功能?

时间:2016-04-23 21:13:53

标签: jquery audio fadein fadeout

我有以下代码在悬停在一个物体上时激活声音,但是想添加简单的淡入和淡出效果(悬停时淡入和淡出时淡出)。会很高兴提示。

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

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

1 个答案:

答案 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)}

由于