垂直滚动无法覆盖

时间:2017-08-23 09:57:37

标签: jquery html css

我正在尝试使用一些背景不透明度覆盖网页,但是当应用叠加层时,网页垂直滚动功能将被禁用。

jQuery和CSS如下:

$(document).ready(function(){
   $("body").append("div").attr("id","overlay");

   $("#overlay").css({
       "position" : "fixed",
       "width" : "100%",
       "height" : "100%",
       "z-index" : "10",
       "background": "#000",
       "opacity": "0.5"  
   });

   $("body").css({
      "overflow-y" : "scroll"
   });

});

1 个答案:

答案 0 :(得分:2)

摘录:

Fiddle



$(document).ready(function(){
$("body").append("div").attr("id","overlay");
$("#overlay").css({
       "position" : "absolute",
       "width" : "100%",
       "height" : "1700px",
       "z-index" : "10",
       "background": "#000",
       "opacity": "0.5"  
    });

    $("body").css({
    "overflow-y" : "scroll"
    });

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;