Web Tutorial 2

Payza Signup
 

HTML5 Server-Sent Events | SSE One Way Messaging | SSE Notifications | SSE Support | SSE Object




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

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:
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:
    EventsDescription
    onopenWhen a connection to the server is opened
    onmessageWhen a message is received
    onerrorWhen an error occurs
    [Read More...]


    HTML5 Web Workers | What is a Web Worker? | Check Web Worker Support | Create a Web Worker File | Create a Web Worker Object | Terminate a Web Worker |



    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

    Web workers are supported in all major browsers, except Internet Explorer.

    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:
    <!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

    [Read More...]


    HTML5 Application Cache | What is Application Cache? | HTML5 Cache Manifest Example | Cache Manifest Basics | The Manifest File | Updating the Cache



    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

    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):
     <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:

    <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" 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 /html/ catalog, in case an internet connection cannot be established:
    FALLBACK:
    /html/ /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:
    /html/ /offline.html
    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).

    [Read More...]


    HTML5 Web Storage - What is HTML5 Web Storage? - localStorage and sessionStorage - localStorage Object - sessionStorage Object



    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

    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.";




    [Read More...]


    HTML5 Geolocation - Locate the User's Position - Handling Errors and Rejections



    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 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:

    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:

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

    var img_url="http://maps.googleapis.com/maps/api/staticmap?center="
    +latlon+"&zoom=14&size=400x300&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).
    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.
    PropertyDescription
    coords.latitudeThe latitude as a decimal number
    coords.longitudeThe longitude as a decimal number
    coords.accuracyThe accuracy of position
    coords.altitudeThe altitude in meters above the mean sea level
    coords.altitudeAccuracyThe altitude accuracy of position
    coords.headingThe heading as degrees clockwise from North
    coords.speedThe speed in meters per second
    timestampThe 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>




    [Read More...]


    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...]


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