[英]Javascript create a responsive container
I have an older website that I need to be made more dynamic. 我有一个较旧的网站,需要使其更具活力。 The website has a graphic chart that is nested inside a div.
该网站有一个嵌套在div中的图形图表。 The problem I have is that there is javascript code that hard codes the height and width of the div container.
我的问题是,有一个JavaScript代码可以对div容器的高度和宽度进行硬编码。 I tried changing the size amount(350) to auto and percentage(10%) but it breaks the program.
我尝试将大小量(350)更改为自动和百分比(10%),但它破坏了程序。 I can't figure out how the program converts the integer value to a pixel value either, but that's probably just my incompetence with javascript.
我也无法弄清楚程序如何将整数值转换为像素值,但这可能仅仅是我对javascript的无能。 I may have missed some important information so let me know if you need anything else.
我可能已经错过了一些重要信息,所以如果您需要其他任何信息,请告诉我。 Thanks
谢谢
Javascript 使用Javascript
var stage = new Kinetic.Stage({
container: 'conKinetic',
width: 1100,
height: 350
});
HTML HTML
<div class='fourthDiv' id="conKinetic">
....This div holds the graphics
</div>
If you are using jQuery, you can set the width and height as percentage and then pass the current pixel units in this way: 如果使用的是jQuery,则可以将宽度和高度设置为百分比,然后以这种方式传递当前像素单位:
var stage = new Kinetic.Stage({
container: 'conKinetic',
width: $('#conKinetic').width(),
height: $('#conKinetic').height()
});
Of course, you can edit the width
or height
values to adapt them to your layout: 当然,您可以编辑
width
或height
值以使其适合您的布局:
width: $('#conKinetic').width() - 50,
Consider this example: 考虑以下示例:
$(document).ready( function() { $('body').append( 'My width is 50%, equivalent to ' + $( '#hi' ).width() + ' px.'); });
body { width: 100%; } #hi { width: 50%; background-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="hi">hello!</div>
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.