如何去掉canvas自动生成的样式?
Chrome:
<canvas id="g_2" width="604" height="304" style="-webkit-user-select: none; touch-action: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 302px; height: 152px;"></canvas>
Firefox:
<canvas height="157" width="1076" style="-moz-user-select: none; width: 302px; height: 152px;" id="g_2"></canvas>
附言:我没有使用任何 javascript 来添加样式。
为了创建 Canvas ,我使用了 angularJS,它使用数组在 canvas 元素上 ng-repeating,以添加新的 canvas ,索引被附加到该数组。这是代码片段:
<div class="tab-content" data-ng-repeat="tab in someArray">
<div role="tabpanel" class="tab-pane active">
<canvas id="someID_[[tab]]"></canvas>
</div>
</div>
创建canvas元素后,设置宽高如下:
var canvas = document.getElementById(canvasId);
canvas.width = width;
canvas.height = height;
最佳答案
当你设置 Canvas 的高度和宽度的同时也设置了它的样式
var canvas = document.getElementById(canvasId);
canvas.width = width;
canvas.height = height;
canvas.style = '';
关于javascript - Canvas : Getting rid of style attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35263214/