简体   繁体   English

jQuery滚动不显示

[英]jQuery scrolling doesn't show up

I'm writting a dynamic page using jQuery and I have a problem. 我正在使用jQuery编写动态页面,但出现了问题。 I'm for example adding to my html file div's using append() function like this: 我例如使用如下的append()函数添加到我的html文件div中:

$("body").append("<div id ='dd_"+i.toString()+"' class='diamond_div'></div>");

I will be creating different amount of that div's base on datebase so that's why I use this variable i to assign different id's for each div. 我将在datebase上创建不同数量的div基础,因此这就是为什么我使用此变量i为每个div分配不同的ID。

My problem is that even if I'm creating that div's in body and when I look at code they are in it, if I check body's height it is 0 (width is ok, something like 1200). 我的问题是,即使我在主体中创建该div,并且当我查看它们所在的代码时,如果我检查主体的高度也为0(宽度可以,例如1200)。 Main problem with that is when there are too many div's they are beyond screen but there is no scroll bar. 主要的问题是,当div太多时,它们超出了屏幕,但是没有滚动条。 It's something like div's aren't in body although in code they are in. Could you propose me any solution for that? 这有点像div不在体内,尽管在代码中它们在其中。您能为此提出任何解决方案吗? Or what am I doing wrong? 还是我做错了什么? My line of thought is that I'm using $(document).ready so html file is creating a page, but see empty body so height = 0 and all my div's are beyond body . 我的思路是,我正在使用$(document).ready,因此html文件正在创建一个页面,但看到的正文为空,因此height = 0且所有div都超出body What do you think about that? 您对此有何看法?

An empty <div> does not have a height. 空的<div>没有高度。 Thus you could add as many as you want to the page and it will never get any longer. 因此,您可以在页面中添加任意数量的页面,并且此页面不再可用。 For the scroll-bar to appear you need to either set a height to the <div> with CSS like this: 为了显示滚动条,您需要使用CSS将高度设置为<div> ,如下所示:

.diamond_div{
    height:100px;
}

Or add some content to the <div> so you would have something like this instead: 或将一些内容添加到<div>这样您将得到以下内容:

$("body").append("<div id ='dd_"+i.toString()+"' class='diamond_div'>hello</div>");

Then your <div> would have height and once there are enough on the page to go beyond the height of the browser, the scroll-bar will then appear. 然后您的<div>将具有高度,并且一旦页面上有足够的空间超出浏览器的高度,滚动条就会出现。


Following on from your comments. 接下来是您的评论。 Setting the position to "fixed" removes the element from the workflow and thus will not extend the length of the page in the normal way. 将位置设置为“固定”会从工作流中删除该元素,因此不会以常规方式延长页面的长度。

Take care of positioning; 注意定位; position:fixed removes your divs from normal flow -> position:fixed将您的div从正常流程中移除->

Fixed positioned elements are removed from the normal flow. 固定位置的元素将从正常流中删除。 The document and other elements behave like the fixed positioned element does not exist. 文档和其他元素的行为就像不存在固定位置的元素。

as W3C says 如W3C所说

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM