Canvas vs. SVG
Canvas
- Elements are drawn programmatically
- Drawing is done with pixels
- Animations are not built in
- High performance for pixels-based drawing operations
- Resolution dependent
- No support for event handlers
- You can save the resulting image as .png or .jpg
- Well suited for graphic-intensive games
SVG
- Elements are part of the page's DOM (Document object model)
- Drawing is done with vectors
- Effects, such as animations are built in
- Based on standard XML syntax, which provides better accessibility
- Resolution independent
- Support for event handlers
- Not suited for game applications
- Best suited for applications with large rendering areas (for example, Google Maps)
You can actually use both SVG and canvas on the same page, if needed.
However, you cannot just draw SVG onto a canvas, or vice-versa.
Which of the following statements are true?
Select all that apply
Working with Canvas
The Canvas element can be transformed. As an example, a text is written on the canvas at the coordinates (10, 30).
Result:
The translate(x,y) method is used to move the Canvas.
x indicates how far to move the grid horizontally, and y indicates how far to move the grid vertically.
In this example, the canvas is moved 100px to the right, and 150px down.
Result:
Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
Which method is used to move the canvas element?
The rotate() Method
The rotate() method is used to rotate the HTML5 Canvas. The value must be in radians, not degrees.
Here is an example that draws the same rectangle before and after rotation is set:
The rotation will only affect drawings made after the rotation is done.
The rotation parameter is in:
The scale() Method
The scale() method scales the current drawing. It takes two parameters:
- The number of times by which the image should be scaled in the X-direction.
- The number of times by which the image should be scaled in the Y-direction.
This will scale the canvas 1.5 times in the X-direction, and 4 times in Y-direction:
If you scale a drawing, all future drawings will also be scaled.
What method is used to increase or decrease the size of the current drawing?
______________________
HTML5 Forms
HTML5 brings many features and improvements to web form creation. There are new attributes and input types that were introduced to help create better experiences for web users.
Form creation is done in HTML5 the same way as it was in HTML4:
Use the novalidate attribute to avoid form validation on submissions.
Fill in the blanks:
<form>
<_____type="text" name="name" />
<_____type="text" name="name" />
</_____>
New Attributes
HTML5 has introduced a new attribute called placeholder. On <input> and <textarea> elements, this attribute provides a hint to the user of what information can be entered into the field.
Result:
The autofocus attribute makes the desired input focus when the form loads:
Result:
The required attribute tells the browser that the input is required.
Drag and drop from the options below to auto focus on the input and create a placeholder:
<form>
<input type="text" name="name"
<input type="text" name="name"
______="Enter your name"
______/>
</form>
autoblur
hint
focus
autofocus
placeholder
Forms with Required Fields
The "required" attribute is used to make the input elements required.
The form will not be submitted without filling in the required fields.
Result:
The autocomplete attribute specifies whether a form or input field should have autocomplete turned on or off.
When autocomplete is on, the browser automatically complete values based on values that the user has entered before.
HTML5 added several new input types:
- color
- date
- datetime
- datetime-local
- month
- number
- range
- search
- tel
- time
- url
- week
New input attributes in HTML5:
- autofocus
- form
- formaction
- formenctype
- formmethod
- formnovalidate
- formtarget
- height and width
- list
- min and max
- multiple
- pattern (regexp)
- placeholder
- required
- step
Input types that are not supported by old web browsers, will behave as input type text.
Designate the username field as required, and focus on the name field when the page loads:
<form autocomplete="off">
<input name="name"
type="text" _____/>
<input name="name"
type="text" _____/>
<br />
<input name="username"
type="text"______/>
<input name="username"
type="text"______/>
</form>
Creating a Search Box
The new search input type can be used to create a search box:
Result:
You must remember to set a name for your input; otherwise, nothing will be submitted.
Fill in the blank to create a Search Box:
<input type="_____"/>
Search Options
The <datalist> tag can be used to define a list of pre-defined options for the search field:
Result:
<option> defines the options in a drop-down list for the user to select.
The ID of the datalist element must match with the list attribute of the input box.
Fill in the blanks to associate the input with the datalist:
<form>
<input type="text" name="color"
<input type="text" name="color"
______="colors" />
<datalist id="_____">
<option value="Red">
<option value="Blue">
<option value="Green">
<option value="Blue">
<option value="Green">
</____>
</form>
Creating More Fields
Some other new input types include email, url, and tel:
These are especially useful when opening a page on a modern mobile device, which recognizes the input types and opens a corresponding keyboard matching the field's type:
These new types make it easier to structure and validate HTML forms.
Which of the following is not a supported type for the input tag?
Which choice is the correct HTML5 element for playing video files?
The <canvas> element in HTML5 is used to:
Which tag contains the navigation?
<____>
sessionStorage stores data for the duration of how many session(s)?
What shape results from the following code?
<svg width="100" height="100">
<line x1="50" y1="0" x2="50" y2="100"
style="stroke:black" />
<line x1="0" y1="50" x2="100" y2="50"
style="stroke:black" />
</svg>
<svg width="100" height="100">
<line x1="50" y1="0" x2="50" y2="100"
style="stroke:black" />
<line x1="0" y1="50" x2="100" y2="50"
style="stroke:black" />
</svg>
No comments:
Post a Comment