为什么下拉菜单消失的速度如此之快?

时间:2016-10-26 23:37:49

标签: html css drop-down-menu menu navigationbar

单击下拉菜单后,下拉菜单即会消失。如何确定此菜单打开的时间长度?我提供了我的javascript,css和html的片段。感谢您的时间。

这是html:

<ul class="navbarWords" id="myNavbarWords">
             <li class="icon">
            <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a>
            </li> 
            <li><a href="daveContact.html">Contact</a></li>
            <li><a href="daveCalendar.html">Calendar</a></li>
            <li><a href="daveTestimonial.html">Testimonials</a></li>  
            <li><a href="daveTips.html">Tips</a></li>
            <li class="dropdown">
                <a href onclick="myFunctions()" class="dropbtn">Gear</a>
                <div id="myDropdown" class="dropdown-content">
                    <a href="#">Link 1</a>
                    <a href="#">Link 2</a>
                    <a href="#">Link 3</a>
                </div>
            </li>
            <li><a href="aboutDave.html">About</a></li>   
            <li><a href="daveCourses.html">Courses</a></li> 


        </ul>
    </div>

这是Css:

.navbar{
            width: 100%;
            clear:both;
            text-align: center;
            background-color: white;
            color: white;
            height: 100px;
            margin: 0px;
            padding-top: 5px;
            padding-bottom: 5px;
            -webkit-box-shadow: 0px 3px 24px -9px rgba(0,0,0,1);
            -moz-box-shadow: 0px 3px 24px -9px rgba(0,0,0,1);
            box-shadow: 0px 3px 24px -9px rgba(0,0,0,1);


        }

       a{
            color:white;

        }

         ul.navbarWords{
            margin: 0;
            padding: 0;
            list-style-type: none;
            z-index:10; 
            position:relative; 

  }
  ul.navbarWords li {
  float: right;

  }
  .navList.responsive{
   margin-top:70px;

    background-color:grey;    
    }


    ul.navbarWords li a {
    text-align: center;
    padding: 14px 16px;
    margin-top:15px;
    transition: 0.3s;
    font-size: 17px;
    display: inline-block;
    color: black;
    font-family: sans-serif;
    text-decoration: none;

 }

 ul.navbarWords li a:hover {
    background-color:#ccc;
    color:#000;
 }

  ul.navbarWords li.icon {
  display: none;


  } 


  @media screen and (max-width:840px) {
  ul.navbarWords li{display: none;}
  ul.navbarWords li.icon {
  float: right;
  display: inline-block;
  right: 0;
  top: 0;
  margin:14px -130px 15px 15px;  
  }
  }
  @media screen and (max-width:840px) {
  ul.navbarWords.responsive  {
  position: relative;
  margin-top:80px;
  background-color:grey;
 }
ul.navbarWords.responsive li.icon {
position:absolute;
right: 0;
top: 0;
margin:-66px 4px 15px 15px;  
}
}
ul.navbarWords.responsive li {
float: none;
display: inline;


}
ul.navbarWords.responsive li a {

  display: block;
text-align: right;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}


  .dropdown-content a {
 color: black;
 padding: 12px 16px;
 text-decoration: none;
 display: block;
 }
.dropdown-content a:hover {background-color: #f1f1f1}
.show {display:block;}

这是javascript:

    function myFunctions() {
document.getElementById("myDropdown").classList.toggle("show");
}


window.onclick = function(e) {
if (!e.target.matches('.dropbtn')) {

var dropdowns = document.getElementsByClassName("dropdown-content");
for (var d = 0; d < dropdowns.length; d++) {
  var openDropdown = dropdowns[d];
  if (openDropdown.classList.contains('show')) {
    openDropdown.classList.remove('show');
   }
  }
 }
}

1 个答案:

答案 0 :(得分:0)

运行中有两个int main() { manager c(10); auto d1 = c.create(5.5); auto d2 = c.create(10.5); auto d3 = c.create(7.5); // Correct behavior if (auto e = d1.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 5.5 if (auto e = d2.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 10.5 if (auto e = d3.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 7.5 std::cout << std::endl; if (auto e = d2.lock()) e->alive = false; // "Kill" the entity c.refresh(); // removes all dead entities. if (auto e = d1.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 5.5 if (auto e = d2.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // Die if (auto e = d3.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 10.5 std::cout << std::endl; c.print(); // Correct behavior, prints only alive entities. std::cout << std::endl; if (auto e = d3.lock()) e->data = 6.5; // Trying to change the value of d3, // which should still be alive. c.print(); std::cout << std::endl; c.grow(10000); if (auto e = d1.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 5.5 if (auto e = d2.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // Die if (auto e = d3.lock()) std::cout << e->data << std::endl; else std::cout << "Die\n"; // 6.5 } 函数:
1. click元素上的onclick="myFunctions()" 2. <a>(捕获文档上的所有点击)。

第一个 - 将window.onclick = function(e) {类添加到您的元素中 第二个 - 删除show类(如果存在)。

你应该决定你想要哪一个以及何时运行它们:)