10+3 EXCELLENT J-QUERY IMAGE SLIDERSA resource list containing awesome jquery sliders, carousels that are free to use and download.
1. Slidorion – NEW
picmale/55m48.jpg
images/website.gif   images/demo.gif

2.Grid Navigation Effects with jQuery – NEW
picmale/55m45.jpg
images/website.gif   images/demo.gif

3. Easy Paginate – NEW
picmale/55m46.jpg
images/website.gif   images/demo.gif

4. Elastic Image Slideshow with Thumbnail Preview – NEW
picmale/55m43.jpg
images/website.gif   images/demo.gif

5.Chop Slider 2 – NEW
picmale/55m42.jpg
images/website.gif   images/demo.gif

6.Orbit: A Slick jQuery Image Slider Plugin – NEW
picmale/55m41.jpg
images/website.gif   images/demo.gif

7.Rotating Image Slider with jQuery – NEW
picmale/55m40.jpg
images/website.gif   images/demo.gif

8.Coin Slider – NEW
picmale/55m38.jpg
images/website.gif   images/demo.gif

9. jqFancyTransitions – NEW
picmale/55m36.jpg
images/website.gif   images/demo.gif

10. Nivo Slider – NEW
picmale/55m37.jpg
images/website.gif   images/demo.gif

11. Agile Carousel – NEW
picmale/55m39.jpg
images/website.gif   images/demo.gif

12.jShowOff: a jQuery Content Rotator – NEW
picmale/55m44.jpg
images/website.gif   images/demo.gif

13.Lemmon Slider – Carousel Supporting Variable Slides/Images Widths – NEW
picmale/55m47.jpg
Rounded Corners with CSS (With No Images)
Rounded corner CSS without images
Rounded Corners:
CSS Rounded Corners for Mozilla Firefox
CSS Rounded Corners for -WEBKIT BROWSERS

Standard: CSS : 

CSS for Standard Corners:
.class {
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px; 
-khtml-border-radius: 15px; /* for old Konqueror browsers */ 
}

CSS for Individual Corners:

.class {
-moz-border-radius-topleft: 15px;
-moz-border-radius-topright: 25px;
-moz-border-radius-bottomright: 35px;
-moz-border-radius-bottomleft: 0;
 
-webkit-border-top-left-radius: 15px;
-webkit-border-top-right-radius: 25px;
-webkit-border-bottom-right-radius: 35px;
-webkit-border-bottom-left-radius: 0;
 
border-top-left-radius: 15px;
border-top-right-radius: 25px;
border-bottom-right-radius: 35px;
border-bottom-left-radius: 0;
}

Short CSS for Rounded Corners:

-moz-border-radius: [top-left] [top-right] [bottom-right] [bottom-left]
Example:  -moz-border-radius: 15px 25px 35px 0;
(Firefox 3.5+):
-moz-border-radius-topleft: [horizontal radius] [vertical radius];
Example: -moz-border-radius-topleft: 10px 40px;
We can write like this also
-moz-border-radius-topleft: 15px 20px;
-moz-border-radius-topright: 25px 35px;
-moz-border-radius-bottomright: 35px 40px;
-moz-border-radius-bottomleft: 45px 65px;
CSS FOR WebKit Elliptical Rounding
All corners:
-webkit-border-radius: 33px 11px;
LEFTcorners only:
-webkit-border-top-left-radius: 52px 32px; 
-webkit-border-bottom-left-radius: 52px 32px;

Print Style Sheet : What is Print Style Sheet ? How to Set up Print Style sheet ?

What is Print Style Sheet ?

A print stylesheet formats a web page so when printed, it automatically prints in a user-friendly format. Print stylesheets have been around for a number of years and have been written about a lot. Yet so few websites implement them, meaning we’re left with web pages that frustratingly don’t properly print on to paper.

How to set up Print Style sheet ?

The best method is to start from scratch and rely on the default style sheet of the browser, which takes care of the printed output pretty well by default. In this case, insert all declarations for printing at the end of your main style sheet, and enclose them with this distinct rule:

@media print {

}


For this we have to do two things 

1. Include all screen styles in the separate @media screen {…} rule;
2. Omit the media type for the condensed style sheet: 
<link rel=”stylesheet” href=”css/style.css”/>

or we can write like this :

<link rel=”stylesheet” href=”print.css” type=”text/css” media=”print” />

 Now ready to add print style sheet ? Thinking about how to write styles?? 
Check the below example: 

   * Remove unwanted elements */
#header, #nav, .noprint
{
display: none;
}

/* Ensure the content spans the full width */
#container, #container2, #content
{
width: 100%; margin: 0; float: none;
}

/* Change text colour to black (useful for light text on a dark background) */
.lighttext
{
color: #000
}

/* Improve colour contrast of links */
a:link, a:visited
{
color: #781351
}

Every thing done, Still have an issue with printing background colors  & Images ?
Here is the solution :

How to get Background Colors & Images in Pirnt ? 
How to get Background Colors & Images in Print pdf file created in Chrome ? 

It’s simple,

Add 
-webkit-print-color-adjust:exact; ” property in body styles.

Ex:
body {background-color:#fff; font-family:arial; font-size:15px; background:white; -webkit-print-color-adjust:exact;

 


 

How to wrap long lines without spaces in HTML?

How to break long urls without spaces in span?

WORD WRAP CSS:
word-wrap: normal | break-word
 

Syntax

word-wrap: normal|break-word;

Description:

This property specifies whether the current rendered line should break if the content exceeds the boundary of the specified rendering box for an element (this is similar in some ways to the ‘clip’ and ‘overflow’ properties in intent.) This property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element.

Examples

div { word-wrap: break-word }
<div style=”word-wrap: break-word”>Here is some content for the div element</div>
Value Description
normal Break words only at allowed break points
break-word Allows unbreakable words to be broken

Javascript Syntax:

object.style.wordWrap=”break-word”

Example

Issue in ie ?  Issue with SPAN tag ? Anchor tag?

Add display :block; property to style to fix the ISSUE:: ENJOY..

Reference: http://www.css3.com/css-word-wrap/

“viewport” meta tag to control layout on mobile devices

<meta name=”viewport” content=”width=device-width”>

General Use of Viewport Tag
Viewport meta tag is generally used for responsive web design to set the viewport width and initial-scale on mobile devices.

The viewport is the logical window in which a web page is designed. We can set the width, height, and initial scale of the viewport for a web page using the viewport property in an HTML <meta> tag.

We can add viewport meta tag in Head tag like this:

<!doctype html><html><head><title>Hello world!</title><metaname="viewport"content="width=device-width, initial-scale=1.0"/></head><body><p>Responsive Web Design!</p></body></html>

Know about Viewport Metatag basics: 
A typical mobile-optimized site contains something like the following:
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>

viewport meta tag supports a handful of other properties for the “content” attribute:
viewport meta tag “content” property attributes
Property Description
width The width of the virtual viewport of the device. Enter a number (pixels assumed), or the keyword “device-width” to set the viewport to the physical width of the device’s screen.
height The height of the virtual viewport of the device. Enter a number (pixels assumed), or the keyword “device-height” to set the viewport to the physical height of the device’s screen.
initial-scale The initial zoom of the webpage, where a value of 1.0 means no zoom.
minimum-scale The minimum level the user is able to zoom out of a webpage, where a value of 1.0 means the user isn’t able to at all.
maximum-scale The maximum level the user is able to zoom in on a webpage, where a value of 1.0 means the user isn’t able to at all.
user-scalable Sets whether the user can zoom in and out of a webpage. Set to yes or no.
When optimizing a webpage for mobile devices, the first step is to add the viewport meta tag to the HEAD section of your page, so that mobile devices refrain from making changes to the zoom level of the webpage unilaterally. In most cases you’ll simply want to set the meta tag’s content property to “width=device-width“, so that no scaling of the page occurs at all, and your CSS media queries will return the actual dimensions of the device, not the “zoomed out” version’s. To also prevent the device from zooming in on a webpage when its orientation has been changed from portrait to landscape and visa versa, you can also throw in an initial-scale and maximum-scale property and limit both of them to 1:
 
 
Webpage rendering at 100% and Scaling Not working for Your web page in Mobile Device ?? 
 
Here is a solution : 
Generally we make a Common Mistake in Adding Viewport tag:
A common mistake is that people often apply initial-scale=1 on non-responsive design. It will make the page render at 100% without scaling. If design is not responsive, users would have to pan around or zoom out to see the full page. The worst case is combining user-scalable=no or maximum-scale=1 with initial-scale=1. It will disable the scaling and zooming capability of site. With scaling disabled, users have no way to zoom out to see the complete page. 
 
Note: if design is not responsive, do not reset the initial-scale or disable scaling!

Keywords:
viewport meta tag to control layout on mobile devices
viewport meta tag Tutorial
viewport meta tag- the key to preparing a page for mobile devices optimization
Webpage rendering at 100% and Scaling Not working for Your web page in Mobile Device ?? 
How to fix Webpage Scaling issue in Mobile  device?
Zooming capability of webpage disabled??

Reference urls:
http://www.javascriptkit.com/dhtmltutors/cssmediaqueries3.shtml 

HTML5: The figure & figcaption elements

Definition and Usage

The <figure> tag specifies self-contained content, like illustrations, diagrams, photos, code listings, etc. While the content of the <figure> element is related to the main flow, its position is independent of the main flow, and if removed it should not affect the flow of the document.

The <figure> tag also supports the Global & Event Attributes in HTML5.

The <figure> element

W3C Says :

The figure element represents a unit of content, optionally with a caption, that is self-contained, that is typically referenced as a single unit from the main flow of the document, and that can be moved away from the main flow of the document without affecting the document’s meaning.

The <figure> element is intended to be used in conjunction with the <figcaption> element to mark up diagrams, illustrations, photos, and code examples (among other things). The spec says this about <figure>:
 

The <figcaption> element

 W3C Says :

The figcaption element represents a caption or legend for a figure.

The <figcaption> element is optional and can appear before or after the content within the <figure>. Only one <figcaption> element may be nested within a <figure>, although the <figure> element itself may contain multiple other child elements (e.g., <img> or <code>). 

Using <figure> and <figcaption>

Want to know how to use ?? Code Examples?
<figure>
 
<img src="/image-name.jpg" alt="Figue Example display">
</figure>
 
Figure with caption Like :
 
<figure>
 
<img src="/macaque.jpg" alt="Macaque in the trees">
 
<figcaption>Lorem Ipsum starts form here. Dummy text. <a href="http://www.google.coml">Google</a></figcaption>
</figure> 
 
 
Multiple Images with Caption :
 
<figure>
 
<img src="/image1.jpg" alt="Kooaburra">
 
<img src="/iamge2.jpg" alt="Pelican stood on the beach">
 
<img src="/image3.jpg" alt="Cheeky looking Rainbow Lorikeet">
 
<figcaption>Signle Caption for multiple Images <a href="http://www.google.com">Fig Caption</a></figcaption>
</figure>

Differences between <figure> and <aside>
 
If the content is simply related and not essential, use <aside>.
If the content is essential but its position in the flow of content isn’t important, use <figure>. 
 
Text Source:
W3schols, W3C,  


 
 
 

1. Flare

A custom responsive, touch enabled, mobile optimized lightbox jQuery plugin, which can be used to display single images/videos or entire galleries.

2. bPopup

Is a lightweight jQuery modal popup plugin (only 1.26KB gzipped). It doesn’t create or style your popup but provides you with all the logic like centering, modal overlay, events and more.

3. FueledWeb Pro Thumbnail Scroller

Is an advanced multipurpose jQuery plugin, html5 thumbnail scroller and image gallery.

4. jQuery YouTube Popup Player Plugin

This is an easy to use jQuery Plugin to embed YouTube videos on your page by displaying them in a popup dialog box.

5. Multipurpose Bookshelf Slider

Is useful for displaying products such as books, magazines, DVD/CD and others.

6. Messi

Is a jQuery plugin to show clean, elegant messages in a simple way.

7. jQuery gzoom plugin

gzoom is a new jquery zoom plugin with following features :
> Click on plus and minus to zoom
> Drag the slider to zoom
> Zoom using mousewheel hover the image
> Moving mouse hover the image change the pan
> Click on the image to show in lightbox style
> jquery.ui framework styled

8. Thumba

Is a gallery jQuery plugin, that displays thumbnails as Google images.

9. jQuery PopBox

Is a simple balloon UI element inspired by 37Signals Highrise CRM.

10. Lytebox

Is a lightweight, cross-browser compatible and mobile friendly JavaScript library and content viewer.
If you enjoyed this post, please support the blog below. It’s FREE!
Get the latest jQuery News, Plugins & Code Snippets FREE via Twitter, our RSS feed, or by email.
http://platform.twitter.com/widgets/follow_button.html#_=1319028559312&align=&button=blue&id=twitter_tweet_button_2&lang=en&link_color=&screen_name=jquery4u&show_count=&show_screen_name=&text_color= subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email
Author: . Find out more about jQuery4u author on  Plus.
Getting Started with MooTools

1. The “Mootorial”

The Mootorial - Screenshot
The Mootorial at //clientside is a comprehensive, practical tutorial on the MooTools framework. The tutorial allows you to execute the sample code either by Firebug or the website’s built-in console.

2. MooTools Overview Video Tutorial

Here’s an excellent screencast that introduces the MooTools framework. It covers the basics such as the concept of chaining, customizing MooTools to your needs, and where to find documentation for MooTools code.

3. Increasing User Experience With Javascript

Increasing User Experience With Javascript - Screenshot
Beauty By Design provides a nine-part video series on improving user interaction using JavaScript (primarily MooTools). A couple of topics covered in the lessons include: using mooTabs, creating sliding sub menus, and using Fx.styles to control font size.

4. Understanding Mootools Selectors

One of the most powerful features of MooTools (as well as other frameworks/libraries like jQuery and Prototype) is the ability to easily select page objects for you to work on. This tutorial covers the basics of selectors in MooTools: $(), $$(), $E(), and $ES() functions.

5. MooTools MooTools Classes: How to use them

This tutorial is an entry-level introduction on working with classes in MooTools. The tutorial works with a hypothetical scenario (buying a car from a car store) to illustrate the concept of classes. The last section of the article discusses the differences of MooTools and script.aculo.us classes.

Intermediate/Advanced Topics

6. Mootools: Ajax and XHR classes

MooTools’ Ajax/XHR classes provides developers a much simpler way of working with XMLHTTPRequests by reducing the amount of code you have to write and by handling browser differences for you. This tutorial talks about the Ajax and XHR classes in brief.

7. Ajax Responder in MooTools

This article delves into the use, extension, and capabilities of the Ajax class in MooTools. It discusses chaining Ajax requests and events, and how you can extend the Ajax class for your needs (also applicable to other MooTools classes).

8. How well do you know Mootools?

Getting started with MooTools is easy, and it won’t be long until you can create wonderful effects and increase user interactivity in your web pages. To help you become a MooTools master, here’s a checklist of common coding mistakes and its corresponding correct usage.

9. Mootools Short-cuts

This is a follow-up article from the one above, focusing more on MooTools syntax usage. Examples involve using shorter code for selection of objects, shorthand for the Ajax class, and creating new elements.

10. Mootools: JSON explained

Mootools: JSON explained - Screenshot
Here’s an excellent introduction to using JSON with MooTools to provide server-side interaction to your web applications. Topics covered include converting a JSON string into a JavaScript object and vice versa.

11. Using MooTools’ Hash.Cookie API

This article explains how to take advantage of MooTools’ powerful Hash.Cookie API to make working with complex cookie utilization a cinch. The example showcases a working example of how you can store the number of times a user visits a page.

12. Chaining with MooTools 1.2

Chaining is beneficial for several reasons including the ability to sequentially execute events (“in a chain”) as well as reduce the number of lines of code you have to write. If you’re wondering about the “who, what, where” of chaining in MooTools, check out this brief but informative tutorial.

Practical/Working Tutorials and Examples

13. AJAX mootools secure contact form

AJAX mootools secure contact form - Screenshot
Learn how to protect your public web forms from spam and SQL injections with this tutorial on how MooTools can be used to make safer public web forms.

14. Using CSS and Mootools to simulate Flash horizontal navigation effect

Using CSS and Mootools to simulate Flash horizontal navigation effect - Screenshot
Create a navigation area that smoothly scrolls left or right depending on where you hover your mouse.

15. Facebook Sliders With Mootools and CSS

Facebook Sliders With Mootools and CSS - Screenshot
Check out this nifty tutorial on how to build a Facebook-inspired set of slider controls that manipulate the opacity, width, and height of an image.

16. MooTools Gone Wild: Element Flashing

MooTools Gone Wild: Element Flashing - Screenshot
In this tutorial, you’ll learn how to make page elements flash. It’s an effective way of drawing attention to a particular section of a web page or alerting users of status changes.

17. Nice Ajax effect for message box using Mootools

Here’s a tutorial on how to display messages that fades in after the user clicks on the submit button. It’s designed for use with web forms, but it can be modified into similar applications.

18. Two CSS vertical menu with show/hide effects

Two CSS vertical menu with show/hide effects - Screenshot
This tutorial shows you how to build a navigation menu that slides up and down smoothly using MooTools. The article also covers how to make a similar effect using plain JavaScript.

19. Mootools Content Slider With Intervals

Mootools Content Slider With Intervals - Screenshot
Here’s an excellent step-by-step tutorial on how to make a content area that slides left-to-right at set intervals – great for slideshows.

20. Jazz Up Your Forms With MooTools

Jazz Up Your Forms With MooTools - Screenshot
This is a two-part series that goes over how to make your web forms fancier. The first part shows you how to add animated field highlighting and how to display instructions to users. In the second part, you’ll step it up a notch by adding live comment previewing and auto-resizing of text areas.
Have you got your own personal MooTools resources to share? Got an interesting MooTools application you want to show us? Talk about it in the comments!
text source:
HTML5 Tutorial, DOCTYPE, HTML5 Video, HTML5 Audio, HTML5 Geolocation, HTML5 Web Storage, HTML5 Application Cache, HTML5 Web Workers Example, HTML5 Server-Sent Events

HTML5 Introduction
HTML5 is the next generation of HTML.

What is HTML5?

HTML5 will be the new standard for HTML.
The previous version of HTML, HTML 4.01, came in 1999. The web has changed a lot since then.
HTML5 is still a work in progress. However, the major browsers support many of the new HTML5 elements and APIs.


How Did HTML5 Get Started?

HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).
WHATWG was working with web forms and applications, and W3C was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.
Some rules for HTML5 were established:

  • New features should be based on HTML, CSS, DOM, and JavaScript
  • Reduce the need for external plugins (like Flash)
  • Better error handling
  • More markup to replace scripting
  • HTML5 should be device independent
  • The development process should be visible to the public

The HTML5 <!DOCTYPE>

In HTML5 there is only one <!doctype> declaration, and it is very simple:

<!DOCTYPE html>

Minimum HTML5 Document

Below is a simple HTML5 document, with the minimum of required tags:

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>

<body>
The content of the document……
</body>

</html>

HTML5 Video

Video on the Web

Until now, there has not been a standard for showing a video/movie on a web page.
Today, most videos are shown 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 a video/movie on a web page: the <video> element.


Browser Support

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


HTML5 Video – How It Works

To show a video in HTML5, this is all you need:

Example

<video width=”320″ height=”240″ controls=”controls”>
<source src=”movie.mp4″ type=”video/mp4″ />
<source src=”movie.ogg” type=”video/ogg” />
Your browser does not support the video tag.
</video>

The control attribute adds video controls, like play, pause, and volume.
It is also a good idea to always include width and height attributes. If height and width are set, the space required for the video is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the video, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the video loads).
You should also insert text content between the <video> and </video> tags for browsers that do not support the <video> element.
The <video> element allows multiple <source> elements. <source> elements can link to different video files. The browser will use the first recognized format.


Video Formats and Browser Support

Currently, there are 3 supported video formats for the <video> element: MP4, WebM, and Ogg:

Browser
MP4
WebM
Ogg
Internet Explorer 9
YES
NO
NO
Firefox 4.0
NO
YES
YES
Google Chrome 6
YES
YES
YES
Apple Safari 5
YES
NO
NO
Opera 10.6
NO
YES
YES
  • MP4 = MPEG 4 files with H264 video codec and AAC audio codec
  • WebM = WebM files with VP8 video codec and Vorbis audio codec
  • Ogg = Ogg files with Theora video codec and Vorbis audio codec

HTML5 Audio

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 Firefox Opera Google Chrome Safari
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
Defines sound content
Defines multiple media resources for media elements, such as <video> and <audio>

HTML5 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 Firefox Opera Google Chrome Safari
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);

The fillStyle attribute makes it red, and the fillRect attribute specifies the shape, position, and size.


Understanding Coordinates

The fillRect property above had the parameters (0,0,150,75).
This means: Draw a 150×75 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.

HTML5 Inline SVG

HTML5 has support for inline SVG.
SVG

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 Firefox Opera Google Chrome Safari
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&#8221; 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>

HTML5 Canvas vs. 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.

Canvas
SVG
  • 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

HTML5 Geolocation

HTML5 Geolocation is used to locate a user’s position Try It

Locate the User’s Position

The HTML5 Geolocation API is used to get the geographical position of a user.
Since this can compromise user privacy, the position is not available unless the user approves it.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari
Internet Explorer 9, Firefox, Chrome, Safari and Opera support Geolocation.
Note: Geolocation is much more accurate for devices with GPS, like iPhone.


HTML5 – Using Geolocation

Use the getCurrentPosition() method to get the user’s position.
The example below is a simple Geolocation example returning the latitude and longitude of the user’s position:

Example

<script>
var x=document.getElementById(“demo”);
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML=”Geolocation is not supported by this browser.”;}
}
function showPosition(position)
{
x.innerHTML=”Latitude: ” + position.coords.latitude +
“<br />Longitude: ” + position.coords.longitude;
}
</script>

Example explained:

  • Check if Geolocation is supported
  • If supported, run the getCurrentPosition() method. If not, display a message to the user
  • If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter ( showPosition )
  • The showPosition() function gets the displays the Latitude and Longitude

The example above is a very basic Geolocation script, with no error handling.


Handling Errors and Rejections

The second parameter of the getCurrentPosition() method is used to handle errors. It specifies a function to run if it fails to get the user’s location:

Example

function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML=”User denied the request for Geolocation.”
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML=”Location information is unavailable.”
break;
case error.TIMEOUT:
x.innerHTML=”The request to get user location timed out.”
break;
case error.UNKNOWN_ERROR:
x.innerHTML=”An unknown error occurred.”
break;
}
}

Error Codes:

  • Permission denied – The user did not allow Geolocation
  • Position unavailable – It is not possible to get the current location
  •  Timeout – The operation timed out

Displaying the Result in a Map

To display the result in a map, you need access to a map service that can use latitude and longitude, like Google Maps:

Example

function showPosition(position)
{
var latlon=position.coords.latitude+”,”+position.coords.longitude;

var img_url=”http://maps.googleapis.com/maps/api/staticmap?center=&#8221;
+latlon+”&zoom=14&size=400×300&sensor=false”;

document.getElementById(“mapholder”).innerHTML=”<img src='”+img_url+”‘ />”;
}

In the example above we use the returned latitude and longitude data to show the location in a Google map (using a static image).
Google Map Script
How to use a script to show an interactive map with a marker, zoom and drag options.


Location-specific Information

This page demonstrated how to show a user’s position on a map. However, Geolocation is also very useful for location-specific information.
Examples:

  • Up-to-date local information
  • Showing Points-of-interest near the user
  • Turn-by-turn navigation (GPS)

The getCurrentPosition() Method – Return Data

The getCurrentPosition() method returns an object if it is successful. The latitude, longitude and accuracy properties are always returned. The other properties below are returned if available.

Property
Description
coords.latitude
The latitude as a decimal number
coords.longitude
The longitude as a decimal number
coords.accuracy
The accuracy of position
coords.altitude
The altitude in meters above the mean sea level
coords.altitudeAccuracy
The altitude accuracy of position
coords.heading
The heading as degrees clockwise from North
coords.speed
The speed in meters per second
timestamp
The date/time of the response

Geolocation object – Other interesting Methods

watchPosition() – Returns the current position of the user and continues to return updated position as the user moves (like the GPS in a car).
clearWatch() – Stops the watchPosition() method.
The example below shows the watchPosition() method. You need an accurate GPS device to test this (like iPhone):

Example

<script>
var x=document.getElementById(“demo”);
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.watchPosition(showPosition);
}
else{x.innerHTML=”Geolocation is not supported by this browser.”;}
}
function showPosition(position)
{
x.innerHTML=”Latitude: ” + position.coords.latitude +
“<br />Longitude: ” + position.coords.longitude;
}
</script>

HTML5 Web Storage

HTML5 web storage, a better local storage than cookies.

What is HTML5 Web Storage?

With HTML5, web pages can store data locally within the user’s browser.
Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website’s performance.
The data is stored in key/value pairs, and a web page can only access data stored by itself.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari
Web storage is supported in Internet Explorer 8+, Firefox, Opera, Chrome, and Safari.
Note: Internet Explorer 7 and earlier versions, do not support web storage.


localStorage and sessionStorage 

There are two new objects for storing data on the client:

  • localStorage – stores data with no expiration date
  • sessionStorage – stores data for one session

Before using web storage, check browser support for localStorage and sessionStorage:

if(typeof(Storage)!==”undefined”)
{
// Yes! localStorage and sessionStorage support!
// Some code…..
}
else
{
// Sorry! No web storage support..
}

The localStorage Object

The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Example

localStorage.lastname=”Smith”;
document.getElementById(“result”).innerHTML=”Last name: ”
+ localStorage.lastname;

Example explained:

  • Create a localStorage key/value pair with key=”lastname” and value=”Smith”
  • Retrieve the value of the “lastname” key and insert it into the element with id=”result”

Tip: Key/value pairs are always stored as strings. Remember to convert them to another format when needed.
The following example counts the number of times a user has clicked a button. In this code the value string is converted to a number to be able to increase the counter:

 

Example

if (localStorage.clickcount)
{
localStorage.clickcount=Number(localStorage.clickcount)+1;
}
else
{
localStorage.clickcount=1;
}
document.getElementById(“result”).innerHTML=”You have clicked the button ” + localStorage.clickcount + ” time(s).”;

The sessionStorage Object

The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.
The following example counts the number of times a user has clicked a button, in the current session:

Example

if (sessionStorage.clickcount)
{
sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
}
else
{
sessionStorage.clickcount=1;
}
document.getElementById(“result”).innerHTML=”You have clicked the button ” + sessionStorage.clickcount + ” time(s) in this session.”;

HTML5 Application Cache

With HTML5 it is easy to make an offline version of a web application, by creating a cache manifest file.

What is Application Cache?

HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection.
Application cache gives an application three advantages:

1.      Offline browsing – users can use the application when they’re offline
2.      Speed – cached resources load faster
3.      Reduced server load – the browser will only download updated/changed resources from the server

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari
Application cache is supported in all major browsers, except Internet Explorer.


HTML5 Cache Manifest Example

The example below shows an HTML document with a cache manifest (for offline browsing):

Example

<!DOCTYPE HTML>
<html manifest=”demo.appcache”>

<body>
The content of the document……
</body>

</html>

Cache Manifest Basics

To enable application cache, include the manifest attribute in the document’s <html> tag:

<!DOCTYPE HTML>
<html manifest=”demo.appcache”>

</html>

Every page with the manifest attribute specified will be cached when the user visits it. If the manifest attribute is not specified, the page will not be cached (unless the page is specified directly in the manifest file).
The recommended file extension for manifest files is: “.appcache”
Remark A manifest file needs to be served with the correct MIME-type, which is “text/cache-manifest”. Must be configured on the web server.


The Manifest File

The manifest file is a simple text file, which tells the browser what to cache (and what to never cache).
The manifest file has three sections:

  • CACHE MANIFEST – Files listed under this header will be cached after they are downloaded for the first time
  • NETWORK – Files listed under this header require a connection to the server, and will never be cached
  • FALLBACK – Files listed under this header specifies fallback pages if a page is inaccessible

CACHE MANIFEST

The first line, CACHE MANIFEST, is required:

CACHE MANIFEST
/theme.css
/logo.gif
/main.js

The manifest file above lists three resources: a CSS file, a GIF image, and a JavaScript file. When the manifest file is loaded, the browser will download the three files from the root directory of the web site. Then, whenever the user is not connected to the internet, the resources will still be available.

NETWORK

The NETWORK section below specifies that the file “login.asp” should never be cached, and will not be available offline:

NETWORK:
login.asp

An asterisk can be used to indicate that all other resources/files require an internet connection:

NETWORK:
*

FALLBACK

The FALLBACK section below specifies that “offline.html” will be served in place of all files in the /html5/ catalog, in case an internet connection cannot be established:

FALLBACK:
/html5/ /offline.html

Note: The first URI is the resource, the second is the fallback.

Updating the Cache

Once an application is cached, it remains cached until one of the following happens:

  • The user clears the browser’s cache
  • The manifest file is modified (see tip below)
  • The application cache is programmatically updated

Example – Complete Cache Manifest File

CACHE MANIFEST
# 2012-02-21 v1.0.0
/theme.css
/logo.gif
/main.js

NETWORK:
login.asp

FALLBACK:
/html5/ /offline.html

Remark Tip: Lines starting with a “#” are comment lines, but can also serve another purpose. An application’s cache is only updated when its manifest file changes. If you edit an image or change a JavaScript function, those changes will not be re-cached. Updating the date and version in a comment line is one way to make the browser re-cache your files.

Notes on Application Cache

Be careful with what you cache. Once a file is cached, the browser will continue to show the cached version, even if you change the file on the server. To ensure the browser updates the cache, you need to change the manifest file.
Note: Browsers may have different size limits for cached data (some browsers have a 5MB limit per site).

HTML5 Web Workers

A web worker is a JavaScript running in the background, without affecting the performance of the page.

What is a Web Worker?

When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.
A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari
Web workers are supported in all major browsers, except Internet Explorer.


HTML5 Web Workers Example

The example below creates a simple web worker that count numbers in the background:

Check Web Worker Support

Before creating a web worker, check whether the user’s browser supports it:

if(typeof(Worker)!==”undefined”)
{
// Yes! Web worker support!
// Some code…..
}
else
{
// Sorry! No Web Worker support..
}

Create a Web Worker File

Now, let’s create our web worker in an external JavaScript.
Here, we create a script that counts. The script is stored in the “demo_workers.js” file:

var i=0;

function timedCount()
{
i=i+1;
postMessage(i);
setTimeout(“timedCount()”,500);
}

timedCount();

The important part of the code above is the postMessage() method – which is used to posts a message back to the HTML page.
Note: Normally web workers are not used for such simple scripts, but for more CPU intensive tasks.


Create a Web Worker Object

Now that we have the web worker file, we need to call it from an HTML page.
The following lines checks if the worker already exists, if not – it creates a new web worker object and runs the code in “demo_workers.js”:

if(typeof(w)==”undefined”)
{
w=new Worker(“demo_workers.js”);
}

Then we can send and receive messages from the web worker.
Add an “onmessage” event listener to the web worker.

w.onmessage=function(event){
document.getElementById(“result”).innerHTML=event.data;
};

When the web worker posts a message, the code within the event listener is executed. The data from the web worker is stored in event.data.


Terminate a Web Worker

When a web worker object is created, it will continue to listen for messages (even after the external script is finished) until it is terminated.
To terminate a web worker, and free browser/computer resources, use the terminate() method:

w.terminate();

Full Web Worker Example Code

We have already seen the Worker code in the .js file. Below is the code for the HTML page:

Example

<!DOCTYPE html>
<html>
<body>

<p>Count numbers: <output id=”result”></output></p>
<button onclick=”startWorker()”>Start Worker</button>
<button onclick=”stopWorker()”>Stop Worker</button>
<br /><br />

<script>
var w;

function startWorker()
{
if(typeof(Worker)!==”undefined”)
{
if(typeof(w)==”undefined”)
{
w=new Worker(“demo_workers.js”);
}
w.onmessage = function (event) {
document.getElementById(“result”).innerHTML=event.data;
};
}
else
{
document.getElementById(“result”).innerHTML=”Sorry, your browser does not support Web Workers…”;
}
}

function stopWorker()
{
w.terminate();
}
</script>

</body>
</html>

Web Workers and the DOM

Since web workers are in external files, they do not have access to the following JavaScript objects:

  • The window object
  • The document object
  • The parent object

HTML5 Server-Sent Events

HTML5 Server-Sent Events allow a web page to get updates from a server.

Server-Sent Events – One Way Messaging

A server-sent event is when a web page automatically gets updates from a server.
This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.
Examples: Facebook/Twitter updates, stock price updates, news feeds, sport results, etc.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari
Server-Sent Events are supported in all major browsers, except Internet Explorer.


Receive Server-Sent Event Notifications

The EventSource object is used to receive server-sent event notifications:

Example

var source=new EventSource(“demo_sse.php”);
source.onmessage=function(event)
{
document.getElementById(“result”).innerHTML+=event.data + “<br />”;
};

Example explained:

  • Create a new EventSource object, and specify the URL of the page sending the updates (in this example “demo_sse.php”)
  • Each time an update is received, the onmessage event occurs
  • When an onmessage event occurs, put the received data into the element with id=”result”

Check Server-Sent Events Support

In the tryit example above there were some extra lines of code to check browser support for server-sent events:

if(typeof(EventSource)!==”undefined”)
{
// Yes! Server-sent events support!
// Some code…..
}
else
{
// Sorry! No server-sent events support..
}

Server-Side Code Example

For the example above to work, you need a server capable of sending data updates (like PHP or ASP).
The server-side event stream syntax is simple. Set the “Content-Type” header to “text/event-stream”. Now you can start sending event streams.
Code in PHP (demo_sse.php):

<?php
header(‘Content-Type: text/event-stream’);
header(‘Cache-Control: no-cache’);

$time = date(‘r’);
echo “data: The server time is: {$time}\n\n”;
flush();
?>

Code in ASP (VB) (demo_sse.asp):

<%
Response.ContentType=”text/event-stream”
Response.Expires=-1
Response.Write(“data: ” & now())
Response.Flush()
%>

Code explained:

  • Set the “Content-Type” header to “text/event-stream”
  • Specify that the page should not cache
  • Output the data to send (Always start with “data: “)
  • Flush the output data back to the web page

The EventSource Object

In the examples above we used the onmessage event to get messages. But other events are also available:

Events
Description
onopen
When a connection to the server is opened
onmessage
When a message is received
onerror
When an error occurs





Text source: http://www.w3schools.com