Web Tutorial 2

Payza Signup
 

0 CSS3 Tutorial | CSS3 Borders | CSS3 Rounded Corners | CSS3 Box Shadow | New Border Properties



CSS3 Tutorial | CSS3 Borders | CSS3 Rounded Corners | CSS3 Box Shadow | New Border Properties

CSS3 Borders
With CSS3, you can create rounded borders, add shadow to boxes, and use an image as a border - without using a design program, like Photoshop.


In this chapter you will learn about the following border properties:

border-radius
box-shadow
border-image

CSS3 Rounded Corners

Adding rounded corners in CSS2 was tricky. We had to use different images for each corner.


In CSS3, creating rounded corners is easy.

In CSS3, the border-radius property is used to create rounded corners:
Example:
Add rounded corners to a div element:

div
{
border:2px solid;
border-radius:25px;
-moz-border-radius:25px; /* Old Firefox */
}


CSS3 Box Shadow

In CSS3, the box-shadow property is used to add shadow to boxes:

Example:
Add a box-shadow to a div element:

div
{
box-shadow: 10px 10px 5px #888888;
}

CSS3 Border Image

With the CSS3 border-image property you can use an image to create a border:

Example:
Use an image to create a border around a div element:

div
{
border-image:url(border.png) 30 30 round;
-moz-border-image:url(border.png) 30 30 round; /* Old Firefox */
-webkit-border-image:url(border.png) 30 30 round; /* Safari and Chrome */
-o-border-image:url(border.png) 30 30 round; /* Opera */
}


New Border Properties

PropertyDescriptionCSS
border-imageA shorthand property for setting all the border-image-* properties3
border-radiusA shorthand property for setting all the four border-*-radius properties3
box-shadowAttaches one or more drop-shadows to the box3


[Read More...]


0 CSS3 Tutorial | CSS3 Introduction | CSS3 Modules | CSS3 Recommendation



CSS3 Tutorial

CSS is used to control the style and layout of Web pages.

CSS3 is the latest standard for CSS.

This tutorial teaches you about the new features in CSS3!
Example:
div
{
transform:rotate(30deg);
}

Here you will find complete CSS3 references of all properties and selectors with syntax, examples, browser support, and more.

CSS3 Introduction

CSS3 is completely backwards compatible, so you will not have to change existing designs. Browsers will always support CSS2.

CSS3 Modules

CSS3 is split up into "modules". The old specification has been split into smaller pieces, and new ones are also added.
Some of the most important CSS3 modules are:
  • Selectors
  • Box Model
  • Backgrounds and Borders
  • Text Effects
  • 2D/3D Transformations
  • Animations
  • Multiple Column Layout
  • User Interface

  • CSS3 Recommendation

    The CSS3 specification is still under development by W3C.
    However, many of the new CSS3 properties have been implemented in modern browsers.
    [Read More...]


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


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


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