/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
body, html {
height: 100%;
}
.parallax {
background-image: url('../images/firstpage.jpg');
height: 100%;
\t margin: 0;
/* Create the parallax scrolling effect */
background-attachment: fixed;
\t
background-position: center;
\t
background-repeat: no-repeat;
\t
background-size: cover;
}
button{
\t background:linear-gradient(to right, rgba(255,0,0,0), rgba(255,255,255,0));
border: none;
\t font-family: "Roboto";
\t color: rgba(0, 0, 0, 0.5);
\t text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.4);
\t text-decoration: none;
\t display: block;
display: inline-block;
font-size: 26px;
\t z-index: 1;
\t float: left;
}
.fixed{
\t position: fixed;
}
.textbackground
{
\t position: absolute;
\t left: 100px;
\t top: 150px;
}
.textbackgroundbar{
\t overflow: hidden;
\t width: 800px;
\t height: 50px;
\t background: linear-gradient(to right,rgba(255,255,255,30), rgba(255,0,0,0), rgba(255,255,255,30));
}
.dropbtn {
display: block;
color: black;
padding: 10px;
font-size: 24px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
\t position: absolute;
\t background: linear-gradient(rgba(0,0,0,0.3),rgba(0,0,0,0.1));
\t min-width: 800px;
\t min-height: 700px;
overflow: auto;
z-index: 1;
}
.dropdown-content a {
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display:block;}
.dropdown-content1 {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown:hover .dropdown-content1 {
display: block;
}
<div class="parallax">
\t <div class="textbackground">
\t <div class="textbackgroundbar">
\t <div class="dropdown">
\t <button onclick="myFunction()" class="dropbtn">Dropdown</button>
\t \t \t <button onclick="myFunction()" class="dropbtn">Dropdown2</button>
\t </div>
\t </div>
<div id="myDropdown" class="dropdown-content">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
\t \t \t \t \t
<div id="myDropdown" class="dropdown-content">
\t <a href="#home">Home2</a>
\t <a href="#about">About2</a>
\t <a href="#contact">Contact2</a>
</div>
</div> \t
</div>
\t
这里有什么问题?它应该下拉2不同的东西,当我点击特定的按钮..但它不。 如果我点击下拉菜单,它会显示关于联系人的主页。如果我点击下拉2,同样的家庭关于联系,但我想它是home2 about2 contact2。整个网站包含5个视差幻灯片。这是一个学校的项目,获得某种许可证,所以我真的想了解该代码(并且大部分是我)。我理解每一个“功能”,但是当我把它们全部合并时......我只是搞砸了。 所以,请尽量清楚。谢谢 ! PS:对不起,我的英语不好,这不是我的第一语言.. :(
谢谢主席先生。我会问另一个小问题。正如你所看到的,如果我点击下拉菜单,它会保持打开状态,直到我再次点击它,但是当我点击Dropdown2并打开Dropdown2时,但它希望它关闭,但它不会。如果我点击Dropdown2,则“文本框”与其他“文本框”重叠。我应该在这里做什么?如果我在菜单栏外单击,“文本框”消失,我怎么能使它消失,当我点击dropdown2呢? – g0dafk
@ g0dafk回答更新,我希望它能解决您的问题。让我知道。 – gaetanoM
是的,它的工作原理! OMG,这很酷,非常感谢你! – g0dafk