【发布时间】:2016-10-03 19:29:32
【问题描述】:
我有一个静音按钮,可以简单地将 HTML5 音频对象静音。它确实使轨道静音,但我喜欢添加淡入/淡出效果。
我通过添加audio.animate({volume: 0}, 2000); 进行了尝试,但它不起作用。
有什么想法吗?
提前致谢!
audio = new Audio();
audio.src = "http://myst729.qiniudn.com/within-temptation_pale.mp3"
audio.play();
$(".mute").on("click tap", function(){
if (audio.muted) {
audio.animate({volume: 1}, 2000);
audio.muted = false;
$(this).text("mute");
} else {
audio.muted = true;
audio.animate({volume: 0}, 2000);
$(this).text("unmute");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="mute">mute</button>
【问题讨论】:
-
把所有东西都放在动画函数中
-
@KarthikeyanSekar 喜欢这个
audio.animate({volume: 1, audio.muted = false}, 2000);?
标签: javascript jquery css html audio