/* 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