【问题标题】:Full Body Overlay With inner divs clickable全身覆盖,内部 div 可点击
【发布时间】:2016-05-29 02:06:25
【问题描述】:

我正在尝试向我的页面添加一个 100% 大小的叠加层。问题是内部 div 和按钮不再可点击。有办法解决吗?

我在这里使用了答案来添加叠加层:CSS: How to get this overlay to extend 100% with scrolling?

我想要实现的就像我们在 Photoshop 中添加到图层/组的蒙版。

谢谢

【问题讨论】:

    标签: html css


    【解决方案1】:

    覆盖层位于按钮容器之上的层上,很可能会拦截指针事件。禁用它们:

    .overlay {
        pointer-events: none;
    }
    

    【讨论】:

      【解决方案2】:

      你需要使用一点 JavaScript 或 JQuery

      这里是带有 JQuery 和 CSS 的 html 页面

       <!doctype html>
      <html lang="en">
        <head>
          <title>
              tester
          </title>
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"> </script>
          <script>
              $(document).ready(function(){
                  $("button").click(function(){
                     $(".overlay").fadeIn();
                     $(".popup").fadeIn();
                  });
      
                   $(".overlay").click(function(){
                     $(".overlay").hide();
                     $(".popup").hide();
                  });
              });
          </script>
      
      
          <style>
              *
              {
                  margin: 0px;
                  padding: 0px;
                  box-sizing: border-box;
                  font-family: "helvetica ";
              }
              button
              {
                  position: absolute;
                  left: 47%;
                  height: 50px;
                  border: none;
                  top: 10%;
                  width: 5%;
                  border-radius: 10px/150px;
                  transition: 0.5s;
                  z-index: -2;
              }
              button:hover
              {
                  cursor: pointer;
                  background: #212121;
                  color: white;
                  font-size: 20px;
              }
      
              .overlay
              {
                  position: fixed;
                  top: 0px;
                  left: 0px;
                  width: 100%;
                  height: 667px;
                  background: black;
                  z-index: 1000;
                  opacity: 0.5;
                  display: none;
              }
      
              .overlay:hover
              {
                  cursor: pointer;
              }
      
              .popup
              {
                  width: 50%;
                  height: 350px;
                  background: white;
                  z-index: 1001;
                  position: absolute;
                  left: 25%;
                  top: 25%;
                  border-radius: 20px;
                  padding:15px;
                  text-align: center;
                  font-size: 36px;
                  display: none;
              }
          </style>
      </head>
      <body>
          <button>
              Pop up
          </button>
      
          <div class="overlay">
      
          </div>
          <div class="popup">
              <p>AM A Pop Up</p>
              <input type="button" value="click me">
          </div>
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-18
        • 2021-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多