컴

HTML5 Canvas Draw Linear Gradient

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

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,417
HTML 17-01-31 조회 2,884
HTML 17-01-27 조회 2,975
HTML 17-01-27 조회 4,100
HTML
[HTML]
17-01-27 조회 2,549
HTML
[HTML]
17-01-26 조회 2,599
HTML 17-01-26 조회 2,147
HTML 17-01-26 조회 2,532
HTML 17-01-24 조회 2,585
HTML 17-01-24 조회 2,761
HTML 17-01-24 조회 2,529
HTML 17-01-22 조회 2,698
HTML 17-01-22 조회 2,954
HTML 17-01-22 조회 2,050
HTML 17-01-19 조회 2,303
HTML 17-01-19 조회 2,291
HTML 17-01-19 조회 2,541
HTML 17-01-18 조회 2,064
HTML 17-01-18 조회 3,087
HTML 17-01-18 조회 2,921
HTML 17-01-17 조회 2,971
HTML 17-01-17 조회 3,271
HTML 17-01-17 조회 2,559
HTML 17-01-16 조회 2,964
HTML 17-01-16 조회 2,501
HTML 17-01-16 조회 2,317
HTML 17-01-14 조회 2,001
HTML 17-01-14 조회 2,263
HTML 17-01-14 조회 2,398
HTML 17-01-13 조회 1,682