【发布时间】:2018-09-09 22:48:06
【问题描述】:
所以我对javascript的了解非常有限,所以我提前为我的愚蠢道歉。
我正在努力使这些警报在网站最初打开后 16 秒播放。在后台,有一个视频正在播放,看起来视频对网站有影响,但实际上,它只是以特定的方式播放。我怎样才能让三个警报在网站打开后 16 秒内播放?你把settimeout放在哪里,或者你把函数的持续时间放在代码的哪里?
再一次,我真的不懂javascript,所以请问我在这段代码中将setTimeout放在哪里?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>eve_</title>
<link rel="icon" rel="preload" href="images/evecircle.png" />
<style>
#video {
margin-left:-10px;
margin-top:-10px;
}
</style>
</head>
<script>
function myText() {
var txt;
var person = prompt("What's your name?", "");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you today?";
}
document.getElementById("demo").innerHTML = txt;
}
function playAlert(msg, wav) {
return new Promise(function(resolve) {
var audio = new Audio(wav);
audio.addEventListener('canplay', function(e) {
audio.play();
alert(msg);
resolve();
});
});
}
playAlert("1", 'Images/thankyou.wav')
.then(function() {
return playAlert("2", 'Images/sorry.wav');
})
.then(function() {
return myText("3", 'Images/mynameiseve.wav');
});
</script>
<body>
<video autoplay="autoplay" preload="metadata" id="video" src="images/secondnew.mp4" width="1300px" height="auto" style="position:absolute; z-index:-1;" >
Video not supported.
</video>
</body>
</html>
【问题讨论】:
标签: javascript function time settimeout alert