javascript - 获取叠加层以向上扩展

标签 javascript html css overlay

this简单的 W3Schools 示例,覆盖从页面顶部开始扩展到底部。怎样才能达到从页面底部开始扩展到顶部的效果呢?

CSS

/* The Overlay (background) */
.overlay {
    /* Height & width depends on how you want to reveal the overlay (see JS below) */    
    height: 0;
    width: 100%;
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    background-color: rgb(0,0,0); /* Black fallback color */
    background-color: rgba(0,0,0, 0.9); /* Black w/opacity */
    overflow-x: hidden; /* Disable horizontal scroll */
    transition: 0.5s; /* 0.5 second transition effect to slide in or slide down the overlay (height or width, depending on reveal) */
}

JavaScript

/* Open */
function openNav() {
    document.getElementById("myNav").style.height = "100%";
}

/* Close */
function closeNav() {
    document.getElementById("myNav").style.height = "0%";
}

HTML

<body>
<!-- The overlay -->
<div id="myNav" class="overlay">

  <!-- Button to close the overlay navigation -->
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</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 -->
<span onclick="openNav()">open</span>
</body>

最佳答案

bottom:0 替换为 top:0

<html><head>
  <style type="text/css">
    
/* The Overlay (background) */
.overlay {
    /* Height & width depends on how you want to reveal the overlay (see JS below) 

*/    
    height: 0;
    width: 100%;
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    bottom: 0;
    background-color: rgb(0,0,0); /* Black fallback color */
    background-color: rgba(0,0,0, 0.9); /* Black w/opacity */
    overflow-x: hidden; /* Disable horizontal scroll */
    transition: 0.5s; /* 0.5 second transition effect to slide in or slide down 

the overlay (height or width, depending on reveal) */
}
  </style>

  <title></title>

  
    




<script type="text/javascript">

/* Open */
function openNav() {
    document.getElementById("myNav").style.height = "100%";
}

/* Close */
function closeNav() {
    document.getElementById("myNav").style.height = "0%";
}
</script>

  
</head>

<body>
  
  




</body>
<body>
<!-- The overlay -->
<div id="myNav" class="overlay">

  <!-- Button to close the overlay navigation -->
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</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 -->
<span onclick="openNav()">open</span>
</body>
</html>

关于javascript - 获取叠加层以向上扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40701182/

相关文章:

javascript - 如何通过单击按钮更改添加元素的顺序?

html - 如何在 mvc 4 中的表单提交上调用 POST Controller 而不是 GET 方法

CSS :hover Selector not working correctly

javascript - 未处理的PromiseRejectionWarning : Unhandled promise rejection (NodeJs, Webdriverio,Selenium)

javascript - Ajax 时不在 chrome 上更新 css

html - Python 3.3.2 - 在 HTML 中查找图像源

html - css div 文本重叠问题

javascript - 平面 UI 复选框样式不起作用

CSS位置问题

javascript - 为桌面使用 1 个内部图像,为移动设备使用不同的内部图像?