javascript - 从顶部效果向下滑动不适用于 JavaScript
问题描述
我期待我的一个按钮能够工作并弹出这些表单,但是每次我点击“更多”按钮时都没有任何反应。请帮忙!
<body>
<!--Hero Image-->
<div class="hero-image">
<div class="hero-text">
<h1 id="demo">Hi! I'm Jake</h1>
<p>Webby web</p>
<!-- The overlay -->
<div id="myNav" class="overlay">
<!-- Button to close the overlay navigation -->
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<!-- Overlay content -->
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<!--Use any element to open/show the overlay navigation menu-->
<button class="button" onclick="myFunction()">More</button>
</div>
</div>
解决方案
您在 JavaScript 中设置了错误的 CSS 属性。应该是display
,不是height
。参见,例如:
document.getElementById("myNav").style.display = "none";
function displayNav() {
document.getElementById("myNav").style.display = "block";
}
function closeNav() {
document.getElementById("myNav").style.display = "none";
}
<!--Hero Image-->
<div class="hero-image">
<div class="hero-text">
<h1 id="demo">Hi! I'm Jake</h1>
<p>Webby web</p>
<!-- The overlay -->
<div id="myNav" class="overlay">
<!-- Button to close the overlay navigation -->
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<!-- Overlay content -->
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<!--Use any element to open/show the overlay navigation menu-->
<button class="button" onclick="displayNav()">More</button>
</div>
</div>
推荐阅读
- java - org.xml.sax.SAXParseException;尝试从请求中获取 xml 输入时文件过早结束
- node.js - 如何在 NodeJS 中使用带有图表和谷歌地图的 html 生成 PDF
- rust - Rust 中结构字段的多态更新
- android - Facebook 广告活动未显示应用安装数据
- c# - 使用 Html.Raw 时如何运行 Html 和 Url 助手 - ASP NET MVC
- excel - Excel:如何将千 (k) 和百万 ($m) 的缩写转换为数值?
- go - Go 中并发数据收集的最佳方式是什么,为什么?
- java - 如何完全阻止 JUnit 套件的执行?
- php - 我正在尝试使用 php 上传音乐和图像文件并插入数据表,但我的代码不起作用
- python - 删除第 n 次出现之前的所有字符