컴

HTML5 Canvas Draw Linear Gradient

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

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,400
HTML 17-01-31 조회 2,866
HTML 17-01-27 조회 2,957
HTML 17-01-27 조회 4,082
HTML
[HTML]
17-01-27 조회 2,521
HTML
[HTML]
17-01-26 조회 2,584
HTML 17-01-26 조회 2,126
HTML 17-01-26 조회 2,518
HTML 17-01-24 조회 2,573
HTML 17-01-24 조회 2,747
HTML 17-01-24 조회 2,512
HTML 17-01-22 조회 2,679
HTML 17-01-22 조회 2,945
HTML 17-01-22 조회 2,037
HTML 17-01-19 조회 2,290
HTML 17-01-19 조회 2,278
HTML 17-01-19 조회 2,529
HTML 17-01-18 조회 2,050
HTML 17-01-18 조회 3,065
HTML 17-01-18 조회 2,904
HTML 17-01-17 조회 2,956
HTML 17-01-17 조회 3,256
HTML 17-01-17 조회 2,546
HTML 17-01-16 조회 2,950
HTML 17-01-16 조회 2,487
HTML 17-01-16 조회 2,306
HTML 17-01-14 조회 1,978
HTML 17-01-14 조회 2,248
HTML 17-01-14 조회 2,381
HTML 17-01-13 조회 1,668