簡體   English   中英

使div用d3填充整個屏幕

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

在jQuery中,這很容易。 只需執行以下操作:

<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>

演示:

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

但是,在D3中,我不太清楚。 這是我在做什么:

<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>

演示:

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

就像div根本沒有調整大小。

那么,如何使用D3處理jquery? 謝謝!

jQuery正在設置CSS高度。 您可以通過以下方法在d3中實現相同的目的:

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

也許您可以使用CSS來做到這一點。 在css文件中:

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

並在html文件中:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM