使内部div可滚动

时间:2017-05-17 11:21:26

标签: javascript jquery html css

当body设置为DIV时,我如何启用内部overflow:hidden上的滚动,因为我有限制编辑正文CSS

以下是JSfiddle demo

Body CSS

body {
    margin: 0;
    padding: 0;
    background-color: #000;
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
}

内部DIV css跟随 - 默认情况下,div的高度由jQuery设置。

.custom-gallery-lineage {
    float: left;
    width: 100%;
    overflow: auto;
    color: #fff;
    font-size: 18px;
}

3 个答案:

答案 0 :(得分:4)

而不是 <span class="additional-background ms-navedit-flyoutArrow"> <span class="menu-item-text">AIRS</span> </span> </a> <ul class="static"> <li class="static"> alert(subListToShow.closest('span .menu-item-text').text()); 您必须使用$(document).height(),请检查以下代码段或更新的小提琴https://jsfiddle.net/sgh1gqh5/2/

$(window).height()
$(document).ready(function() {
	var winw = $(window).width();
	var winh = $(window).height();
	$(".custom-gallery-lineage").height(winh);
});
body {
	margin: 0;
	padding: 0;
	background-color: #000;
	overflow: hidden;
	max-width: 100%;
	max-height: 100%;
}
.custom-gallery-lineage {
	float: left;
	width: 100%;
	overflow: auto;
	color: #fff;
	font-size: 18px;
}

答案 1 :(得分:2)

问题是因为您要将元素的height设置为与document匹配。相反,请使用window

$(document).ready(function() {
  var winw = $(window).width();
  var winh = $(window).height();
  $(".custom-gallery-lineage").height(winh);
});

更好的是,根本不使用JS,并使用CSS中的vh单位设置高度:

&#13;
&#13;
body {
  margin: 0;
  padding: 0;
  background-color: #000;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}

.custom-gallery-lineage {
  float: left;
  width: 100%;
  overflow: auto;
  color: #fff;
  font-size: 18px;
  height: 100vh;
}
&#13;
<div class="custom-gallery-lineage">
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
  <p>This is test content</p>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

试试这个

&#13;
&#13;
$(document).ready(function() {
	var winw = $(document).width();
	var winh = $(window).height();
	$(".custom-gallery-lineage").height(winh);
});
&#13;
&#13;
&#13;

相关问题