画布:摆脱样式属性

时间:2016-02-08 05:57:19

标签: javascript css html5 canvas

如何摆脱画布自动生成的风格?

public void webService_GetProductsCompleted(object sender, CatalogueServiceReference.GetProductsCompletedEventArgs e)
{
    if (e.Result.Count != 0)
    {
        PagedCollectionView pagingCollection = new PagedCollectionView(e.Result);
        pgrProductGrids.Source = pagingCollection;
        grdProductGrid.ItemsSource = pagingCollection;
        pgrProductGrids.Visibility = Visibility.Visible;
    }
}

P.S:我没有使用任何javascript来添加样式。

要创建画布,我使用angularJS,它使用数组在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>

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

1 个答案:

答案 0 :(得分:1)

设置画布高度和宽度时,还要设置其样式

var canvas = document.getElementById(canvasId); 
canvas.width = width; 
canvas.height = height;
canvas.style = '';