컴

HTML5 Canvas Draw Linear Gradient

· 2017-01-22 (일) 16:16:42 · 2699

HTML5 Canvas Draw Linear Gradient

 

 

Example

var c = document.getElementById("myCanvas");

var ctx = c.getContext("2d");

 

// Create gradient

var grd = ctx.createLinearGradient(0,0,200,0);

grd.addColorStop(0,"red");

grd.addColorStop(1,"white");

 

// Fill with gradient

ctx.fillStyle = grd;

ctx.fillRect(10,10,150,80)

 

65defb0327642f480c2599904de52fad_1485069399_3614.PNG
 

 

<!DOCTYPE html>

<html>

<body>

 

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">

Your browser does not support the HTML5 canvas tag.</canvas>

 

<script>

var c = document.getElementById("myCanvas");

var ctx = c.getContext("2d");

// Create gradient

var grd = ctx.createLinearGradient(0,0,200,0);

grd.addColorStop(0,"red");

grd.addColorStop(1,"white");

// Fill with gradient

ctx.fillStyle = grd;

ctx.fillRect(10,10,150,80);

</script>

 

</body>

</html>


|
댓글을 작성하시려면 로그인이 필요합니다.

퍼블리셔팁

1,282건

퍼블리싱과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
HTML 17-01-31 조회 2,419
HTML 17-01-31 조회 2,886
HTML 17-01-27 조회 2,976
HTML 17-01-27 조회 4,101
HTML
[HTML]
17-01-27 조회 2,550
HTML
[HTML]
17-01-26 조회 2,601
HTML 17-01-26 조회 2,148
HTML 17-01-26 조회 2,533
HTML 17-01-24 조회 2,586
HTML 17-01-24 조회 2,762
HTML 17-01-24 조회 2,530
HTML 17-01-22 조회 2,700
HTML 17-01-22 조회 2,955
HTML 17-01-22 조회 2,052
HTML 17-01-19 조회 2,304
HTML 17-01-19 조회 2,292
HTML 17-01-19 조회 2,542
HTML 17-01-18 조회 2,065
HTML 17-01-18 조회 3,088
HTML 17-01-18 조회 2,923
HTML 17-01-17 조회 2,971
HTML 17-01-17 조회 3,272
HTML 17-01-17 조회 2,560
HTML 17-01-16 조회 2,965
HTML 17-01-16 조회 2,503
HTML 17-01-16 조회 2,319
HTML 17-01-14 조회 2,002
HTML 17-01-14 조회 2,264
HTML 17-01-14 조회 2,400
HTML 17-01-13 조회 1,683