JavaScript fillStyle 可以与中风()一起使用吗?

标签 javascript html

在 JavaScript 中,是否可以在 lines() 中使用任何类型的 fillStyle
这是我的代码:

var text = document.getElementById("text");
var first = text.getContext("2d");
first.font = "100px SimLLHP";
first.strokeStyle = "blue";
first.strokeText("T1",100,100);
var last = text.getContext("2d");
last.font = "100px SimLLHP";
last.strokeStyle = "blue";
last.strokeText("T2",110,180)

最佳答案

不,不是。 linesfill 都有自己的属性和方法,以便在 HTML5 Canvas 上绘图。 lines 用于轮廓,例如轮廓或线条。以及实体形状的fill。因此,fillStyle 仅用于填充,而 StrokeStyle 用于笔划。没有理由将它们混合在一起。

因此,如果您想填充文本,那么我们只需使用 fillStylefillText 即可。

var last = text.getContext("2d");
last.font = "100px SimLLHP";
last.fillStyle = "blue";
last.fillText("T2",110,180)

Fiddle 1

假设我们希望它被填充并有一个轮廓,那么我们首先进行填充,然后描边

// I hope you don't mind me using "ctx", it's the most common.
var ctx = text.getContext("2d");
ctx.font = "100px SimLLHP";
ctx.fillStyle = "blue";
ctx.fillText("T2",10,100);
ctx.strokeStyle = "red";
ctx.strokeText("T2",10,100);

Fiddle 2

关于JavaScript fillStyle 可以与中风()一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24946312/

相关文章:

javascript - 在 iOS 上将视频流式传输到浏览器

javascript - 如何在 Angular 2 中使用 vanilla js/es6 的 bootstrap?

javascript - Vuejs Prop 不断变化

Javascript 播放器不适用于 Opera/Chrome

html - 重新定义选择器以用于其余代码的不同方式

html - 全屏垂直居中 HTML 页面的方法?

javascript - 可以用 JQuery 缩短这个 Javascript 吗?

javascript - 如何在Vue完全加载和初始化后才运行VueJS代码?

javascript - 如何使用 onchange 传递多个字段

javascript - 如何在 chrome 中禁用或隐藏弹出退出全屏(F11)?