У меня был быстрый вопрос относительно функции ctx stroke
наряду с использованием rect
. В моем коде я нарисую rect
и залейте его красным. Я хочу также добавить зеленый границы вокруг rect
, но когда я использую stroke
, кажется, что создается прозрачная рамка, а не сплошная линия. Почему он делает это по умолчанию?Ход контекста контекста() делает прозрачную рамку, а не полностью непрозрачной?
Img результата:
Мой код:
var ctx = Canvas.ctx;
ctx.beginPath();
ctx.rect(this.x, this.y, this.width, this.height);
/*
* CONTAINER
*/
ctx.fillStyle = this.primaryColor;
ctx.fill();
/*
* CONTAINER BAR
*/
if(this.borderColor){
ctx.strokeStyle = this.borderColor;
ctx.stroke();
}
/*
* INNER BAR
*/
var per = this.percent;
if(per > 0){
//the width of the actual loading bar that appears
//inside the entire box
var innerWidth = Math.floor(this.width*(per/100));
ctx.fillStyle = this.secondaryColor;
ctx.fillRect(this.x+1, this.y+1, innerWidth-2, this.height-2);
}
/*
* TEXT
*/
if(this.text){
ctx.textAlign = this.textAlign;
ctx.font = this.font;
ctx.fillStyle = this.textColor;
ctx.fillText(this.text, this.textX, this.textY);
}