[英]How to stop audio alert?
我有一个警报框和一个声音警报。 单击警报框的关闭图像时,我要停止音频警报。 我已经做到了 警报框和音频警报均正确出现。 但是音频会在发出哔声后立即停止(即在关闭警报消息之前)。
<script type="text/javascript" src="jquery-1.2.3.pack.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//first slide down and blink the alert box
$("#object").animate({
top: "0px"
}, 2000).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
//stop the audio alarm
//close the message box when the cross image is clicked
$("#close_message").click(function()
{
audio.pause(); //stop the audio alarm
$("#object").fadeOut("slow");
});
});
</script>
if($a>$B)
{
echo " <script> var audio = document.createElement('audio');
document.body.appendChild(audio);
audio.src = '/sounds-990-system-fault.mp3';
audio.addEventListener('canplaythrough', function() {
audio.play();
}, 5000);
</script>";
echo '<div id="object" class="message">' ;
echo '<img id="close_message" style="float:right;cursor:pointer" src="12-em-cross.png" />';
echo '<strong>Failed </strong>';
echo '</div>';
}
向您的音频元素添加一个loop
属性就足够了。 这样,声音将不确定地播放,直到您通过代码实际暂停它为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.