2017-02-20 56 views
2

如何在画布上的文字达致这文字阴影

textarea 
 
{text-shadow:white 0px 1px 0px, white 0px -1px 0px, white -1px 0px 0px, white 1px 0px 0px, white -1px 1px 0px, white 1px 1px 0px, white -1px -1px 0px, white 1px -1px 0px, white 0px 1.5px 0px, white 0px -1.5px 0px, white -1.5px 0px 0px, white 1.5px 0px 0px, white -1.5px 1.5px 0px, white 1.5px 1.5px 0px, white -1.5px -1.5px 0px, white 1.5px -1.5px 0px, rgb(133, 133, 133) 0px -1px 4px, rgb(133, 133, 133) 0px 3px 4px, rgb(133, 133, 133) 3px 0px 4px, rgb(133, 133, 133) -3px 0px 4px; 
 
color:red; 
 
}
<textarea >default text in the textarea 
 
</textarea>

如何在画布文本应用此文字阴影。我搜索了各种方式,如(http://jsfiddle.net/DirkWeber/nnqc8/1/light/),我无法在画布文本中复制这种类型的文字阴影。请让我知道如何做到这一点。

+0

使用阴影,填充颜色,笔画颜色和笔画宽度的混合[近似您的效果](https://jsfiddle.net/r2apkwh0/1/)...根据需要调整字体大小 – markE

回答

3

Canvas example

var canvas = document.getElementsByTagName("canvas")[0], 
 
    ctx = canvas.getContext('2d'); 
 

 
ctx.font="75px verdana"; 
 
ctx.shadowColor="black"; 
 
ctx.shadowBlur=10; 
 
ctx.lineWidth=10; 
 
ctx.strokeStyle = "white"; 
 
ctx.strokeText("HELLO",25,100); 
 
ctx.shadowBlur=0; 
 
ctx.fillStyle="red"; 
 
ctx.fillText("HELLO",25,100);
<canvas id="c" width="300" height="130"></canvas>

CSS例如

.text {font-size: 3em; 
 
    -webkit-text-stroke: 2px white; 
 
    -webkit-text-fill-color: black; 
 
    -webkit-animation: fill 1s infinite alternate; 
 
text-shadow:2px 2px 10px #000; 
 
}
<div class="text">default text in the textarea 
 
</div>

+0

不完全。但你将如何实现这一目标? – Ashokkumar

+0

我可以帮你澄清你想要做什么。 – cnsvnc

+0

喜欢这个。 https://jsfiddle.net/5wh3mjpz/你能帮忙吗? – Ashokkumar