Web Tutorial 2

Payza Signup
 

HTML5 Canvas vs. SVG - SVG - Canvas - Comparison of Canvas and SVG



Both canvas and SVG allow you to create graphics inside the browser, but they are fundamentally different.

SVG

SVG is a language for describing 2D graphics in XML.
SVG is XML based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.
In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.

Canvas

Canvas draws 2D graphics, on the fly (with a JavaScript).
Canvas is rendered pixel by pixel.
In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic.

Comparison of Canvas and SVG

The table below shows some important differences between canvas and SVG.
CanvasSVG
  • Resolution dependent
  • No support for event handlers
  • Poor text rendering capabilities
  • You can save the resulting image as .png or .jpg
  • Best suited for graphic-intensive games where many objects are redrawn frequently
  • Resolution independent
  • Support for event handlers
  • Best suited for applications with large rendering areas (Google Maps)
  • Slow rendering if complex (anything that uses the DOM a lot will be slow)
  • Not suited for game applications

[Read More...]


HTML5 Inline SVG - What is SVG? - SVG Advantag - Browser Supportes - Embed SVG Directly Into HTML Pages - Example - SVG Elements




What is SVG?


  • SVG stands for Scalable Vector Graphics
  • SVG is used to define vector-based graphics for the Web
  • SVG defines the graphics in XML format
  • SVG graphics do NOT lose any quality if they are zoomed or resized
  • Every element and every attribute in SVG files can be animated
  • SVG is a W3C recommendation

SVG Advantages

Advantages of using SVG over other image formats (like JPEG and GIF) are:
  • SVG images can be created and edited with any text editor
  • SVG images can be searched, indexed, scripted, and compressed
  • SVG images are scalable
  • SVG images can be printed with high quality at any resolution
  • SVG images are zoomable (and the image can be zoomed without degradation)

Browser Support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support inline SVG.

Embed SVG Directly Into HTML Pages

In HTML5, you can embed SVG elements directly into your HTML page:

Example:

<!DOCTYPE html>
<html>
<body>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">
  <polygon points="100,10 40,180 190,60 10,60 160,180"
  style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>

</body>
</html>


Result:



SVG Reference:

SVG Elements


ElementDescriptionAttributes
<a>Creates a link around SVG elementsxlink:show
xlink:actuate
xlink:href
target
<altGlyph>Provides control over the glyphs used to render particular character datax
y
dx
dy
rotate
glyphRef
format
xlink:href
<altGlyphDef>Defines a substitution set for glyphsid
<altGlyphItem>Defines a candidate set of glyph substitutionsid
<animate>Defines how an attribute of an element changes over timeattributeName="the name of the target attribute"
from="the starting value"
to="the ending value"
dur="the duration"
repeatCount="the number of time the animation will take place"
<animateColor>Defines a color transformation over timeby="a relative offset value"
from="the starting value"
to="the ending value"
<animateMotion>Causes a referenced element to move along a motion pathcalcMode="the interpolation mode for the animation. Can be 'discrete', 'linear', 'paced', 'spline'"
path="the motion path"
keyPoints="how far along the motion path the object shall move at the moment in time"
rotate="applies a rotation transformation"
xlink:href="an URI reference to the <path> element which defines the motion path"
<animateTransform>Animates a transformation attribute on a target element, thereby allowing animations to control translation, scaling, rotation and/or skewingby="a relative offset value"
from="the starting value"
to="the ending value"
type="the type of transformation which is to have its values change over time. Can be 'translate', 'scale', 'rotate', 'skewX', 'skewY'"
<circle>Defines a circlecx="the x-axis center of the circle"
cy="the y-axis center of the circle"
r="The circle's radius". Required.

+ presentation attributes:
Color, FillStroke, Graphics
<clipPath>Clipping is about hiding what normally would be drawn. The stencil which defines what is and what isn't drawn is called a clipping pathclip-path="the referenced clipping path is intersected with the referencing clipping path"
clipPathUnits="'userSpaceOnUse' or 'objectBoundingBox'. The second value makes units of children a fraction of the object bounding box which uses the mask (default: 'userSpaceOnUse')"
<color-profile>Specifies a color profile description (when the document is styled using CSS)local="the unique ID for a locally stored color profile"
name=""
rendering-intent="auto|perceptual|relative-colorimetric|saturation|absolute-colorimetric"
xlink:href="the URI of an ICC profile resource"
<cursor>Defines a platform-independent custom cursorx="the x-axis top-left corner of the cursor (default is 0)"
y="the y-axis top-left corner of the cursor (default is 0)"
xlink:href="the URI of the image to use as the cursor
<defs>A container for referenced elements
<desc>A text-only description for container elements or graphic elements in SVG (user agents may display the text as a tooltip)
<ellipse>Defines an ellipsecx="the x-axis center of the ellipse"
cy="the y-axis center of the ellipse"
rx="the length of the ellipse's radius along the x-axis". Required.
ry="the length of the ellipse's radius along the y-axis". Required.

+ presentation attributes:
Color, FillStroke, Graphics
<feBlend>Composes two objects together according to a certain blending modemode="the image blending modes: normal|multiply|screen|darken|lighten"
in="identifies input for the given filter primitive: SourceGraphic | SourceAlpha | BackgroundImage | BackgroundAlpha | FillPaint | StrokePaint | <filter-primitive-reference>"
in2="the second input image to the blending operation"
feColorMatrixSVG filter. Applies a matrix transformation
feComponentTransferSVG filter. Performs component-wise remapping of data
feCompositeSVG filter.
feConvolveMatrixSVG filter.
feDiffuseLightingSVG filter.
feDisplacementMapSVG filter.
feDistantLightSVG filter. Defines a light source
feFloodSVG filter.
feFuncASVG filter. Sub-element to feComponentTransfer
feFuncBSVG filter. Sub-element to feComponentTransfer
feFuncGSVG filter. Sub-element to feComponentTransfer
feFuncRSVG filter. Sub-element to feComponentTransfer
feGaussianBlurSVG filter. Performs a Gaussian blur on the image
feImageSVG filter.
feMergeSVG filter. Creates image layers on top of each other
feMergeNodeSVG filter. Sub-element to feMerge
feMorphologySVG filter. Performs a "fattening" or "thinning" on a source graphic
feOffsetSVG filter. Moves an image relative to its current position
fePointLightSVG filter.
feSpecularLightingSVG filter.
feSpotLightSVG filter.
feTileSVG filter.
feTurbulenceSVG filter.
filterContainer for filter effects
fontDefines a font
font-faceDescribes the characteristics of a font
font-face-format
font-face-name
font-face-src
font-face-uri
foreignObject
<g>Used to group together elementsid="the name of the group"
fill="the fill color for the group"
opacity="the opacity for the group"

+ presentation attributes:
All
glyphDefines the graphics for a given glyph
glyphRefDefines a possible glyph to use
hkern
<image>Defines an imagex="the x-axis top-left corner of the image"
y="the y-axis top-left corner of the image"
width="the width of the image". Required.
height="the height of the image". Required.
xlink:href="the path to the image". Required.

+ presentation attributes:
Color, Graphics, Images, Viewports
<line>Defines a linex1="the x start point of the line"
y1="the y start point of the line"
x2="the x end point of the line"
y2="the y end point of the line"

+ presentation attributes:
Color, FillStroke, Graphics, Markers
<linearGradient>Defines a linear gradient. Linear gradients fill the object by using a vector, and can be defined as horizontal, vertical or angular gradients.id="the unique id used to reference this pattern. Required to reference it"
gradientUnits="'userSpaceOnUse' or 'objectBoundingBox'. Use the view box or object to determine relative position of vector points. (Default 'objectBoundingBox')"
gradientTransform="the transformation to apply to the gradient"
x1="the x start point of the gradient vector (number or % - 0% is default)"
y1="the y start point of the gradient vector. (0% default)"
x2="the x end point of the gradient vector. (100% default)"
y2="the y end point of the gradient vector. (0% default)"
spreadMethod="'pad' or 'reflect' or 'repeat'"
xlink:href="reference to another gradient whose attribute values are used as defaults and stops included. Recursive"
<marker>Markers can be placed on the vertices of lines, polylines, polygons and paths. These elements can use the marker attributes "marker-start", "marker-mid" and "marker-end"' which inherit by default or can be set to 'none' or the URI of a defined marker. You must first define the marker before you can reference it via its URI. Any kind of shape can be put inside marker. They are drawn on top of the element they are attached tomarkerUnits="'strokeWidth' or 'userSpaceOnUse'. If 'strokeWidth' is used then one unit equals one stroke width. Otherwise, the marker does not scale and uses the the same view units as the referencing element (default 'strokeWidth')"
refx="the position where the marker connects with the vertex (default 0)"
refy="the position where the marker connects with the vertex (default 0)"
orient="'auto' or an angle to always show the marker at. 'auto' will compute an angle that makes the x-axis a tangent of the vertex (default 0)"
markerWidth="the width of the marker (default 3)"
markerHeight="the height of the marker (default 3)"
viewBox="the points "seen" in this SVG drawing area. 4 values separated by white space or commas. (min x, min y, width, height)"

+ presentation attributes:
All
<mask>Masking is a combination of opacity values and clipping. Like clipping you can use shapes, text or paths to define sections of the mask. The default state of a mask is fully transparent which is the opposite of clipping plane. The graphics in a mask sets how opaque portions of the mask aremaskUnits="'userSpaceOnUse' or 'objectBoundingBox'. Set whether the clipping plane is relative the full view port or object (default: 'objectBoundingBox')"
maskContentUnits="Use the second with percentages to make mask graphic positions relative the object. 'userSpaceOnUse' or 'objectBoundingBox' (default: 'userSpaceOnUse')"
x="the clipping plane of the mask (default: -10%)"
y="the clipping plane of the mask (default: -10%)"
width="the clipping plane of the mask (default: 120%)"
height="the clipping plane of the mask (default: 120%)"
metadataSpecifies metadata
missing-glyph
mpath
<path>Defines a pathd="a set of commands which define the path"
pathLength="If present, the path will be scaled so that the computed path length of the points equals this value"
transform="a list of transformations"

+ presentation attributes:
Color, FillStroke, Graphics, Markers
<pattern>Defines the coordinates you want the view to show and the size of the view. Then you add shapes into your pattern. The pattern repeats when an edge of the view box (viewing area) is hitid="the unique id used to reference this pattern." Required.
patternUnits="'userSpaceOnUse' or 'objectBoundingBox'. The second value makes units of x, y, width, height a fraction (or %) of the object bounding box which uses the pattern."
patternContentUnits="'userSpaceOnUse' or 'objectBoundingBox'"
patternTransform="allows the whole pattern to be transformed"
x="pattern's offset from the top-left corner (default 0)"
y="pattern's offset from the top-left corner. (default 0)"
width="the width of the pattern tile (default 100%)"
height="the height of the pattern tile (default 100%)"
viewBox="the points "seen" in this SVG drawing area. 4 values separated by white space or commas. (min x, min y, width, height)"
xlink:href="reference to another pattern whose attribute values are used as defaults and any children are inherited. Recursive"
<polygon>Defines a graphic that contains at least three sidespoints="the points of the polygon. The total number of points must be even". Required.
fill-rule="part of the FillStroke presentation attributes"

+ presentation attributes:
Color, FillStroke, Graphics, Markers
<polyline>Defines any shape that consists of only straight linespoints="the points on the polyline". Required.

+ presentation attributes:
Color, FillStroke, Graphics, Markers
<radialGradient>Defines a radial gradient. Radial gradients are created by taking a circle and smoothly changing values between gradient stops from the focus point to the outside radius.gradientUnits="'userSpaceOnUse' or 'objectBoundingBox'. Use the view box or object to determine relative position of vector points. (Default 'objectBoundingBox')"
gradientTransform="the transformation to apply to the gradient"
cx="the center point of the gradient (number or % - 50% is default)"
cy="the center point of the gradient. (50% default)"
r="the radius of the gradient. (50% default)"
fx="the focus point of the gradient. (0% default)"
fy="The focus point of the gradient. (0% default)"
spreadMethod="'pad' or 'reflect' or 'repeat'"
xlink:href="Reference to another gradient whose attribute values are used as defaults and stops included. Recursive"
<rect>Defines a rectanglex="the x-axis top-left corner of the rectangle"
y="the y-axis top-left corner of the rectangle"
rx="the x-axis radius (to round the element)"
ry="the y-axis radius (to round the element)"
width="the width of the rectangle". Required.
height="the height of the rectangle" Required.

+ presentation attributes:
Color, FillStroke, Graphics
scriptContainer for scripts (e.g., ECMAScript)
setSets the value of an attribute for a specified duration
<stop>The stops for a gradientoffset="the offset for this stop (0 to 1/0% to 100%)". Required.
stop-color="the color of this stop"
stop-opacity="the opacity of this stop (0 to 1)"
styleAllows style sheets to be embedded directly within SVG content
<svg>Creates an SVG document fragmentx="top left corner when embedded (default 0)"
y="top left corner when embedded (default 0)"
width="the width of the svg fragment (default 100%)"
height="the height of the svg fragment (default 100%)"
viewBox="the points "seen" in this SVG drawing area. 4 values separated by white space or commas. (min x, min y, width, height)"
preserveAspectRatio="'none' or any of the 9 combinations of 'xVALYVAL' where VAL is 'min', 'mid' or 'max'. (default xMidYMid)"
zoomAndPan="'magnify' or 'disable'. Magnify option allows users to pan and zoom your file (default magnify)"
xml="outermost <svg> element needs to setup SVG and its namespace: xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve""

+ presentation attributes:
All
switch
symbol
<text>Defines a textx="a list of x-axis positions. The nth x-axis position is given to the nth character in the text. If there are additional characters after the positions run out they are placed after the last character. 0 is default"
y="a list of y-axis positions. (see x). 0 is default"
dx="a list of lengths which moves the characters relative to the absolute position of the last glyph drawn. (see x)"
dy="a list of lengths which moves the characters relative to the absolute position of the last glyph drawn. (see x)"
rotate="a list of rotations. The nth rotation is performed on the nth character. Additional characters are NOT given the last rotation value"
textLength="a target length for the text that the SVG viewer will attempt to display the text between by adjusting the spacing and/or the glyphs. (default: The text's normal length)"
lengthAdjust="tells the viewer what to adjust to try to accomplish rendering the text if the length is specified. The two values are 'spacing' and 'spacingAndGlyphs'"

+ presentation attributes:
Color, FillStroke, Graphics, FontSpecification, TextContentElements
textPath
titleA text-only description for elements in SVG - not displayed as part of the graphics. User agents may display the text as a tooltip
<tref>References any <text> element in the SVG document and reuse itIdentical to the <text> element
<tspan>Identical to the <text> element but can be nested inside text tags and inside itselfIdentical to the <text> element
+ in addition:
xlink:href="Reference to a <text> element"
<use>Uses a URI to reference a <g>, <svg> or other graphical element with a unique id attribute and replicate it. The copy is only a reference to the original so only the original exists in the document. Any change to the original effects all copies.x="the x-axis top-left corner of the cloned element"
y="the y-axis top-left corner of the cloned element"
width="the width of the cloned element"
height="the height of the cloned element"
xlink:href="a URI reference to the cloned element"

+ presentation attributes:
All
view
vkern

[Read More...]


HTML5 Canvas - What is Canvas?



The <canvas> element is used to draw graphics, on the fly, on a web page.

What is Canvas?

The HTML5 <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript).
The <canvas> element is only a container for graphics, you must use a script to actually draw the graphics.
A canvas is a drawable region defined in HTML code with height and width attributes.
Canvas has several methods for drawing paths, boxes, circles, characters, and adding images.

Browser Support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the <canvas> element.
Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.

Create a Canvas

A canvas is specified with the <canvas> element.
Specify the id, width, and height of the <canvas> element:

<canvas id="myCanvas" width="200" height="100"></canvas>

Draw With JavaScript

The <canvas> element has no drawing abilities of its own.
All drawing must be done inside a JavaScript:
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="#FF0000";
ctx.fillRect(0,0,150,75);
</script>
JavaScript uses the id to find the <canvas> element:
var c=document.getElementById("myCanvas");
Then, create a context object:
var ctx=c.getContext("2d");
The getContext("2d") object is a built-in HTML5 object, with many methods to draw paths, boxes, circles, characters, images and more.
The next two lines draws a red rectangle:
ctx.fillStyle="#FF0000";
ctx.fillRect(0,0,150,75);

Understanding Coordinates

The fillRect property above had the parameters (0,0,150,75).
This means: Draw a 150x75 rectangle on the canvas, starting at the top left corner (0,0).
The canvas' X and Y coordinates are used to position drawings on the canvas.

More Canvas Examples
Below are more examples of drawing on the <canvas> element:

Example - Line

Your browser does not support the HTML5 canvas tag.

Example - Circle

Your browser does not support the HTML5 canvas tag.

Example - Gradient

Your browser does not support the HTML5 canvas tag.

Example - Image

Your browser does not support the HTML5 canvas tag.

HTML5 <canvas> Tag

Tag Description
<canvas>Used to draw graphics, on the fly, via scripting (usually JavaScript)

HTML5 canvas.getContext("2d") reference

Description

The HTML5 <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).
However, the <canvas> element has no drawing abilities of its own (it is only a container for graphics) - you must use a script to actually draw the graphics.
The getContext() method returns an object that provides methods and properties for drawing on the canvas.
This reference will cover the attributes and methods of the getContext("2d") object, which can be used to draw lines, boxes, circles, and more - on the canvas.

Colors and Styles

Property Value Description
fillStyle color
gradient
pattern
Sets or returns the fill style of the drawing
strokeStyle color
gradient
pattern
Sets or returns the stroke style of the drawing
lineCap butt
round
square
Sets or returns the style of the ending of a line
lineJoin bevel
round
miter
Sets or returns the type of corner created, when two lines meet
lineWidth number Sets or returns the width of the stroke
miterLimit number Sets or returns the limit size of the corners in a line
shadowColor color Sets or returns the color of the shadow
shadowOffsetX number Sets or returns the horizontal distance of the shadow
shadowOffsetY number Sets or returns the vertical distance of the shadow
shadowBlur number Sets or returns the size of the blurring effect

Method Description
createLinearGradient() Creates a gradient object. Use this object as a value to the strokeStyle or fillStyle attributes
createPattern() Creates a pattern from an image to be used by the fillStyle or strokeStyle attributes
createRadialGradient() Creates a gradient object as a circle. Use this object as a value to the strokeStyle or fillStyle attributes
addColorStop() Specifies the gradient's position and color
drawCustomFocusRing(element)
drawSystemFocusRing(element)

Path, Curve, Circle, and Rectangle

Method Description
fillRect(x,y,w,h) Draws a filled rectangle using the color/style of the fillStyle attribute
strokeRect(x,y,w,h) Draws the lines of a rectangle using the color/style of the strokeStyle attribute
clearRect(x,y,w,h) Clears a rectangle area. All pixels inside this area will be erased
beginPath() Starts a new path, or clears the current path
moveTo(x,y) Moves the path to the specified point, without creating a line
closePath() Creates a line (path) from the last point in the path, to the first point. Completes the path
lineTo(x,y) Creates a line from the last point in the path to the given point
rect(x,y,w,h) Creates a rectangle
fill() Fills the current path with the selected color, black is default
stroke() Creates a stroke/path described with the specified path methods
clip() Creates an area in the canvas, and this area is the only visible area in the canvas
quadraticCurveTo(cpx,cpy,x,y) Creates a quadratic Bezier curve from the current point in the path to the specified path
bezierCurveTo(cpx,cpy,cpx,cpy,x,y) Creates a cubic Bezier curve from the current point in the path to the specified path
arc(x,y,r,sAngle,eAngle,aClockwise) Creates a circle, or parts of a circle
arcTo(x1,y1,x2,y2,radius) Creates an arc between two points
isPointInPath(x,y) Returns a Boolean value, true if the specified point is in the path, otherwise false

Transformations

Method Description
scale(x,y) Scales the drawings based on the x and y parameters
rotate(angle) Rotates the drawings based on the given angle
translate(x,y) Moves the drawings horizontally and vertically
transform(a,b,c,d,e,f) Changes the shape of the drawings based on a matrix
setTransform(a,b,c,d,e,f) Clears the current transformation, then makes the changes of the drawings based on a matrix

Text

Property Value Description
font fontproperties Specifies font properties used for writing on the canvas
textAlign start
end
left
right
center
The alignment of the text, "start" is default
textBaseline alphabetic
bottom
hanging
ideographic
middle
top
The vertical alignment of the text, "alphabetic" is default

Method Description
fillText(text,x,y,maxWidth) Draws text on the canvas, and fills it with the color set by the fillStyle attribute
strokeText(text,x,y,maxWidth) Draws text on the canvas, without filling, using the color set by the strokeStyle attribute.
measureText(text).width Measures the given text string, returns the result in pixels

Images and Pixel Manipulation

Property Value Description
width number Specifies the width of the imagedata object
height number Specifies the height of the imagedata object
data array An array containing the rgba values of all pixels in an imagedata object

Method Description
drawImage() Use a picture when drawing onto the canvas
createImageData() Creates a blank imagedata object
getImageData(x,y,w,h) Creates a new imagedata object, containing data from the canvas
putImageData(imgdat,dx,dy,x,y,w,h) Draws imagedata onto the canvas

Compositing

Property Value Description
globalAlpha number Specifies the transparency of the drawings
globalCompositeOperation source-atop
source-in
source-out
source-over
destination-atop
destination-in
destination-out
destination-over
lighter
copy
xor
vendorName-operationName
Specifies how shapes and drawings are positioned onto the canvas, source-over is default
[Read More...]


HTML5 Drag and Drop - Drag and Drop



Drag and Drop

Drag and drop is a very common feature. It is when you "grab" an object and drag it to a different location.
In HTML5, drag and drop is part of the standard, and any element can be draggable.

Browser Support

Internet Explorer 9, Firefox, Opera 12, Chrome, and Safari 5 support drag and drop.
Note: Drag and drop does not work in Safari 5.1.2.

HTML5 Drag and Drop Example

The example below is a simple drag and drop example:

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function allowDrop(ev)
{
ev.preventDefault();
}

function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}

function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<div id="div1" ondrop="drop(event)"
ondragover="allowDrop(event)"></div>
<img id="drag1" src="img_logo.gif" draggable="true"
ondragstart="drag(event)" width="336" height="69" />

</body>
</html>

It might seem complicated, but lets go through all the different parts of a drag and drop event.

Make an Element Draggable

First of all: To make an element draggable, set the draggable attribute to true:
<img draggable="true" />

What to Drag - ondragstart and setData()

Then, specify what should happen when the element is dragged.
In the example above, the ondragstart attribute calls a function, drag(event), that specifies what data to be dragged.
The dataTransfer.setData() method sets the data type and the value of the dragged data:
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}

Where to Drop - ondragover

The ondragover event specifies where the dragged data can be dropped.
By default, data/elements cannot be dropped in other elements. To allow a drop, we must prevent the default handling of the element.
This is done by calling the event.preventDefault() method for the ondragover event:
event.preventDefault()

Do the Drop - ondrop

When the dragged data is dropped, a drop event occurs.
In the example above, the ondrop attribute calls a function, drop(event):
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
Code explained:
  • Call preventDefault() to prevent the browser default handling of the data (default is open as link on drop)
  • Get the dragged data with the dataTransfer.getData("Text") method. This method will return any data that was set to the same type in the setData() method
  • The dragged data is the id of the dragged element ("drag1")
  • Append the dragged element into the drop element
[Read More...]


HTML5 Audio - Audio on the Web



Audio on the Web

Until now, there has not been a standard for playing audio files on a web page.
Today, most audio files are played through a plug-in (like flash). However, different browsers may have different plug-ins.
HTML5 defines a new element which specifies a standard way to embed an audio file on a web page: the <audio> element.

Browser Support

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the <audio> element.
Note: Internet Explorer 8 and earlier versions, do not support the <audio> element.

HTML5 Audio - How It Works

To play an audio file in HTML5, this is all you need:
Example:
<audio controls="controls">
  <source src="song.ogg" type="audio/ogg" />
  <source src="song.mp3" type="audio/mpeg" />
  Your browser does not support the audio element.
</audio> 
The control attribute adds audio controls, like play, pause, and volume.
You should also insert text content between the <audio> and </audio> tags for browsers that do not support the <audio> element.
The <audio> element allows multiple <source> elements. <source> elements can link to different audio files. The browser will use the first recognized format.

Audio Formats and Browser Support

Currently, there are 3 supported file formats for the <audio> element: MP3, Wav, and Ogg:
Browser MP3 Wav Ogg
Internet Explorer 9 YES NO NO
Firefox 4.0 NO YES YES
Google Chrome 6 YES YES YES
Apple Safari 5 YES YES NO
Opera 10.6 NO YES YES

HTML5 Audio Tags

Tag Description
<audio> Defines sound content
<source> Defines multiple media resources for media elements, such as <video> and <audio>

 


 

[Read More...]


 
Payza Signup
Return to top of page Copyright © 2011 | Web Tutorial 2 Sponsored byTuli Host BD