admin管理员组文章数量:1391951
I want to resize this Canvas width but I can't. No matter what - canvas width is 100% of the screen... Changing width and height changes only the ratio. Maybe someone know where is the problem?
<canvas id="ini" width="500" height="300"></canvas>
/
.js-RangeSlider
I want to resize this Canvas width but I can't. No matter what - canvas width is 100% of the screen... Changing width and height changes only the ratio. Maybe someone know where is the problem?
<canvas id="ini" width="500" height="300"></canvas>
https://jsfiddle/schme16/xfyvvup8/20/
https://github./schme16/Chart.js-RangeSlider
Share Improve this question asked Mar 20, 2017 at 2:31 Darius KaziukevičiusDarius Kaziukevičius 411 silver badge3 bronze badges 1-
just pass
responsive: false
option in yourchartOptions
dict. jsfiddle/xfyvvup8/89 – Kaiido Commented Mar 20, 2017 at 6:48
2 Answers
Reset to default 5I would guess that the charting library that you are using is doing some resizing. But since I don't have time to read the library's code, here is a workaround for you:
<div class="container">
<canvas id="ini" width="500" height="300"></canvas>
</div>
.container {
width: 500px;
}
That is, put the canvas element inside another element with a fixed width.
Demo: https://jsfiddle/xfyvvup8/88/
You can use the .height
and .width
property of the canvas DOM for this. It can be as same as the height and width attributes. You'll need to give numeric values in the JS code ti resize.
var canvas = document.getElementsByTagName('canvas')[0];
canvas.height = 500;
canvas.width = 500;
These are the logical dimensions for the canvas. Now you can set the .style.height
and .style.width
CSS attributes. If you don't set up the style attributes then the intrinsic size of the canvas will be used as the display size.
Then again, if you set up the CSS attributes and they differ from the canvas dimensions, your content will be rendered and scaled by the browser. Suppose you add these lines with the above.
canvas.style.width = '750px';
canvas.style.height = '500px';
本文标签: javascriptHTML Canvas Width can39t be resizedStack Overflow
版权声明:本文标题:javascript - HTML Canvas Width can't be resized - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744718247a2621538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论