【问题标题】:how to add fade in and fade out function to play on hover function?如何添加淡入淡出功能以在悬停功能上播放?
【发布时间】:2016-04-23 21:13:52
【问题描述】:
我有以下代码在悬停在对象上时激活声音,但想添加简单的淡入和淡出效果(在悬停时淡入和在悬停时淡出)。会很高兴得到提示。
function PlaySound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.play()}
function StopSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.pause();
thissound.currentTime = 0;}
【问题讨论】:
标签:
jquery
audio
fadein
fadeout
【解决方案1】:
谢谢。
它似乎仍然不起作用。我更正了广告首先尝试的一些事情:
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)}
谢谢