DevelopPHP
home gear home donate
Search Results For
in:

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting Developer Q+A
HTML canvas example   Share / Like

NOTE: This new element is HTML5 and will be a standardized element in 2014.

The <canvas> tag is aptly named. It supplies us with a means of drawing things through script and it renders in a browser. Much the same way one would use Actionscript to animate the Flash stage. Things can be stationary or animated inside of a canvas tag. We use Javascript to draw what we want in the canvas and animate those things. Interaction and Event listeners can also be applied to canvas elements using Javascript.

We have a few video tutorials covering the HTML 5 <canvas> tag that you may find insightful:
HTML 5 Canvas Tag Tutorial Learn to Draw and Animate Using Javascript
HTML 5 Canvas Tutorial Draw Lines and Filled Shapes Using Javascript
HTML 5 Canvas Fallback Content Tutorial Show Alternate Content No Browser Support

HTML CODE EXAMPLE
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript" language="javascript">
window.onload = draw; // Execute draw function when DOM is ready
function draw() {
// Assign our canvas element to a variable
var canvas = document.getElementById("canvas1");
// Create the HTML5 context object to enable draw methods
var ctx = canvas.getContext("2d");
// Draw Filled Shape 1 (center triangle of logo)
ctx.beginPath();
ctx.moveTo(100, 50);
ctx.lineTo(130, 100);
ctx.lineTo(70, 100);
ctx.fillStyle = "rgba(0,0,0,1)";
ctx.fill();
// Draw Filled Shape 2 (left flap of logo)
ctx.beginPath();
ctx.moveTo(72, 60);
ctx.lineTo(85, 72);
ctx.lineTo(71, 94);
ctx.lineTo(50, 70);
ctx.lineTo(65, 40);
ctx.fillStyle = "rgba(0,0,0,1)";
ctx.fill();
// Your homework is to Draw Filled Shape 3 here (right flap)
// to complete the shape of the WorldOfWebcraft.com logo
}
</script>
</head>
<body>
<canvas id="canvas1" width="400" height="300">Fallback Content</canvas>
</body>
</html>

Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
DevelopPHP.com is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2013 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at WebIntersect.com.
©2014 DevelopPHP.com HTML5