简体   繁体   English

使div用d3填充整个屏幕

[英]making a div fill the entire screen with d3

In jquery it's easy enough. 在jQuery中,这很容易。 Just do the following: 只需执行以下操作:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<body style="margin: 0; padding: 0">
<div id="test" style="background: black"></div>
</body>

<script>
$('#test').width($(window).width());
$('#test').height("100%");
</script>

Demo: 演示:

http://www.frostjedi.com/terra/scripts/demo/fullsize-jquery.html http://www.frostjedi.com/terra/scripts/demo/fullsize-jquery.html

In D3, however, it's not quite as clear to me. 但是,在D3中,我不太清楚。 Here's what I'm doing: 这是我在做什么:

<script src="http://d3js.org/d3.v3.min.js"></script>
<body style="margin: 0; padding: 0">
<div id="test" style="background: black"></div>
</body>

<script>
d3.select("#test").attr("width", window.innerWidth);
d3.select("#test").attr("height", "100%");
</script>

Demo: 演示:

http://www.frostjedi.com/terra/scripts/demo/fullsize-d3.html http://www.frostjedi.com/terra/scripts/demo/fullsize-d3.html

It's like the div isn't being resized at all. 就像div根本没有调整大小。

So how do I do, with D3, what I'm doing with jquery? 那么,如何使用D3处理jquery? Thanks! 谢谢!

The jquery is setting the css height. jQuery正在设置CSS高度。 You can achieve the same thing in d3 by: 您可以通过以下方法在d3中实现相同的目的:

d3.select("#test").style("height", "100%");

maybe you can use css to do this. 也许您可以使用CSS来做到这一点。 in the css file: 在css文件中:

#fullScreen{
    position:absolute;
    left:0;
    right:0;
    top:0;
    bottom:0;
    background-color:#000;
}

and in the html file: 并在html文件中:

<body>
    <div id="fullScreen"></div>
</body>

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

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