컴

HTML5 Canvas Draw Linear Gradient

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

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,426
HTML 17-01-31 조회 2,890
HTML 17-01-27 조회 2,980
HTML 17-01-27 조회 4,109
HTML
[HTML]
17-01-27 조회 2,558
HTML
[HTML]
17-01-26 조회 2,609
HTML 17-01-26 조회 2,157
HTML 17-01-26 조회 2,538
HTML 17-01-24 조회 2,592
HTML 17-01-24 조회 2,769
HTML 17-01-24 조회 2,535
HTML 17-01-22 조회 2,703
HTML 17-01-22 조회 2,960
HTML 17-01-22 조회 2,059
HTML 17-01-19 조회 2,310
HTML 17-01-19 조회 2,297
HTML 17-01-19 조회 2,548
HTML 17-01-18 조회 2,071
HTML 17-01-18 조회 3,091
HTML 17-01-18 조회 2,930
HTML 17-01-17 조회 2,977
HTML 17-01-17 조회 3,276
HTML 17-01-17 조회 2,568
HTML 17-01-16 조회 2,970
HTML 17-01-16 조회 2,507
HTML 17-01-16 조회 2,333
HTML 17-01-14 조회 2,006
HTML 17-01-14 조회 2,270
HTML 17-01-14 조회 2,406
HTML 17-01-13 조회 1,690