HTML5 to draw text with effect in canvas

Source: Internet
Author: User

first, draw the text

Two methods are provided in the drawing environment for drawing text in canvas.

Stroketext (text,x,y): Draws hollow text at (x,y).
Filltext (text,x,y): (x,y) draws a solid text.

second, draw text in canvas

The

code is as follows:


<! DOCTYPE html>


<html>


<head>


<meta http-equiv= "Content-type" content= "text/html"; CharSet = utf-8 ">


<title>HTML5</title>


<script type= "text/javascript" charset = "Utf-8" >


//This function will be called after the page is fully loaded


function pageLoaded ()


{


//Get a reference to the canvas object, notice that the Tcanvas name must be the same as the ID in the following body


var canvas = document.getElementById (' Tcanvas ');


//Get the 2D drawing environment of the canvas


var context = Canvas.getcontext (' 2d ');


//Drawing code will appear here


//Draw text


Context.filltext (' Welcome to Dujun Blog ', 100,40);


//Modify Font


Context.font = ' 20px Arial ';


Context.filltext (' Welcome to Dujun Blog ', 100,100);


//Draw Hollow text


Context.font = ' 36px official script ';


Context.stroketext (' Welcome to Benedict's Blog ', 100,200);


}


</script>


</head>


<body onload= "pageLoaded ();" >


<canvas width = "height" = "$" id = "Tcanvas" style = "border:black 1px solid;" >


<!--Displays the following font if the browser does not support-->


Tip: Your browser does not support <canvas> tags


</canvas>


</body>


</html>


third, the drawing effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.