javascript - .getElementById 在文档中找不到 id
问题描述
我正在为学校比赛设置一个网页,我想编写一些代码,当鼠标悬停在页脚上时,它将扩展到全屏。
我已经编写了代码,但是其中一个 JavaScript.getElementById()
函数无法使用 id 脚找到我的页脚。
const footer = document.getElementById("foot");
footer.addEventListener("mouseenter", fullscreen);
footer.addEventListener("mouseleave", original);
function fullscreen() {
footer.classList.add("fullscreen");
footer.classList.remove("original");
}
function original() {
footer.classList.add("original");
footer.classList.remove("fullscreen");
}
@keyframes fullscreen {
from {height: 10vh};
to {height: 100vh};
}
@keyframes original {
from {height: 100vh};
to{height: 10vh};
}
.fullscreen {
animation-name: fullscreen;
animation-duration: 1500ms;
}
.original {
animation-name: original;
animation-duration: 1500ms;
}
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<footer id="foot">
<a href="#top"><h2>Let's Go</h2></a>
</footer>
</body>
</html>
解决方案
推荐阅读
- c - C 错误:此处不允许函数定义,我已经将函数放在 int main(void) 之上,删除了括号,错误仍然存在
- reactjs - React useReducer 中的问题
- ruby - Ruby/Watir 禁用保存密码提示
- javascript - 如何解决错误“此表达式不可构造”?
- flutter - Flutter 底部导航栏
- java - 更新云 Firestore 中的字段键
- azure-log-analytics - Azure Log Analytics - KQL - 获取年初至今计数的查询
- apache-kafka - Confluent 5.5.1 无法启动 Kafka Rest,Kafka 服务器未运行。错误:退出状态 127
- salesforce - 显示空白值的电子邮件模板。显示文本但字段值为空白
- c - 结构的静态数组与带有 libaio 的结构的 malloc 数组