使用js// 1、加载页面后,呈现蓝色填充文字“敲回车看好戏”(见常量START_TEXT), // 字体大小为46像素(TEXT_SIZE); // 2、敲击键盘回车后,逐步出现戴口罩的小女孩(images/ex2-1.jpg); // 3、小女孩图像显示完整后,过1秒后出现1米小剧场的漫画图(images/ex2-2.jpg); // 4、1秒后,出现蓝色填充的“谢谢观看”文字(见常量END_TEXT); // 5、效果请见demo2(视频演示)。
时间: 2023-03-30 15:04:35 浏览: 85
回答:
可以使用以下代码实现:
const START_TEXT = "敲回车看好戏";
const TEXT_SIZE = "46px";
const END_TEXT = "谢谢观看";
// 加载页面后,呈现蓝色填充文字“敲回车看好戏”
document.body.style.backgroundColor = "blue";
const startText = document.createElement("div");
startText.innerText = START_TEXT;
startText.style.fontSize = TEXT_SIZE;
startText.style.color = "white";
document.body.appendChild(startText);
// 敲击键盘回车后,逐步出现戴口罩的小女孩
document.addEventListener("keydown", function(event) {
if (event.code === "Enter") {
const girlImage = document.createElement("img");
girlImage.src = "images/ex2-1.jpg";
girlImage.style.opacity = ;
document.body.appendChild(girlImage);
let opacity = ;
const intervalId = setInterval(function() {
opacity += .1;
girlImage.style.opacity = opacity;
if (opacity >= 1) {
clearInterval(intervalId);
// 小女孩图像显示完整后,过1秒后出现1米小剧场的漫画图
setTimeout(function() {
const theaterImage = document.createElement("img");
theaterImage.src = "images/ex2-2.jpg";
theaterImage.style.opacity = ;
document.body.appendChild(theaterImage);
let opacity = ;
const intervalId = setInterval(function() {
opacity += .1;
theaterImage.style.opacity = opacity;
if (opacity >= 1) {
clearInterval(intervalId);
// 1秒后,出现蓝色填充的“谢谢观看”文字
setTimeout(function() {
const endText = document.createElement("div");
endText.innerText = END_TEXT;
endText.style.fontSize = TEXT_SIZE;
endText.style.color = "white";
endText.style.backgroundColor = "blue";
endText.style.textAlign = "center";
endText.style.position = "absolute";
endText.style.top = "50%";
endText.style.left = "50%";
endText.style.transform = "translate(-50%, -50%)";
document.body.appendChild(endText);
}, 100);
}
}, 100);
}, 100);
}
}, 100);
}
});
阅读全文