GoalKicker.com – HTML5 Canvas
Notes for Professionals
4
var
ctx
=
canvas.
getContext
(
"2d"
);
var
ox
=
canvas.
width
/
2
;
var
oy
=
canvas.
height
/
2
;
ctx.
font
=
"42px serif"
;
ctx.
textAlign
=
"center"
;
ctx.
textBaseline
=
"middle"
;
ctx.
fillStyle
=
"#800"
;
ctx.
fillRect
(
ox
/
2
,
oy
/
2
,
ox
,
oy
);
download_img
=
function
(
el
)
{
// get image URI from canvas object
var
imageURI
=
canvas.
toDataURL
(
"image/jpg"
);
el.
href
=
imageURI
;
};
Live demo
on JSfiddle.
Section 1.5: How to add the Html5 Canvas Element to a
webpage
Html5-Canvas ...
Is an Html5 element.
Is supported in most modern browsers (Internet Explorer 9+).
Is a visible element that is transparent by default
Has a default width of 300px and a default height of 150px.
Requires JavaScript because all content must be programmatically added to the Canvas.
Example: Create an Html5-Canvas element using both Html5 markup and JavaScript:
>
body{ background-color:white; }
#canvasHtml5{border:1px
solid red; }
#canvasJavascript{border:1px solid blue; }
window.onload=(function(){
// add a canvas
element using javascript
var canvas=document.createElement('canvas');
canvas.id='canvasJavascript'
document.body.appendChild(canvas);
}); // end $(function(){});
Dostları ilə paylaş: