RoundAbout With Colors Using HTML 5

Introduction

 
In this article, we are going to understand the roundabout using HTML 5. The application works like the animated cursor that changes position and also changes the color of the pointer that is sliding when you click on any of the circles.
 
Here we will use some JavaScript and some styles along with the HTML code. Just go through the steps to see how to create this application.
 
Let's see how the playground application can be created. To do so go through the following steps. 
 
Step 1 : Open a HTML editor or Visual Studio.
 
sd.gif
 
Open File menu ->select new ->Choose Website then. 
 
0000.jpg
 
This is where we will create an HTML5 application.
  • Go to Solution Explorer
  • Right-click on the Application name
  • Select Add-->add new item
  • Now in the window that opens, select an HTML page or news Webform
  • Rename it by roundaboutpointer.aspx
rd0.gif
 
Step 2: In this section, we will create the style for the media and create the .css on the media screen. Put the given script in the Head section of the HTML or in between the <head>--</head>.
 
Here two CSS files are used for design purposes; one is for the section div, named d1.css and the other d2.css for the whole body of the web page. 
 
d1.css scripting
  1. body  
  2. {   
  3.    background: #FFFF99;   
  4.     color: #fff;   
  5.     font: 300 100.1% "Helvetica Neue" , Helvetica, "Arial Unicode MS" , Arial, sans-serif;   
  6. }   
  7. #holder  
  8. {   
  9.     height: 442px;   
  10.     left: 42%;   
  11.     margin: -240px 0 0 -320px;   
  12.     position: absolute;   
  13.     top: 57%;   
  14.     width: 842px;   
  15.     font-size: x-large;   
  16.     background-color: #008000;   
  17. }   
  18. #duplicate   
  19. {   
  20.     bottom: 0;   
  21.     font: 300 .7em "Helvetica Neue", Helvetica, ;   
  22.     position: absolute;   
  23.     right: 1em;   
  24.     text-align: right;  
  25. }   
  26. #duplicate d   
  27. {   
  28.     color: #fff;  
  29. }  
d2.css scripting
  1. body {   
  2.     background: #fff;   
  3.     color: #000;   
  4.     font: 100.1% "Comic Sans MS", Lucida, Verdana, sans-serif;   
  5. }   
  6. #holder   
  7. {  
  8.     height: 480px;   
  9.     left: 50%;   
  10.     margin: 0 0 0 -320px;   
  11.     position: absolute;   
  12.     top: 0;   
  13.     width: 640px;   
  14. }   
  15. #duplicate   
  16. {   
  17.     bottom: 0;   
  18.     font-size: .7em;   
  19.     position: absolute;   
  20.     right: 1em;   
  21.     text-align: right;   
  22. }  
Step 3: In this part, we need to work on some JavaScript over here. For understanding the full working of JavaScript download the attached .rar file and run the playground application.
 
The whole JavaScript looks as follows.
  1. window.onload = function ()   
  2. {  
  3.    var r = Color("holder", 640, 480),  
  4.    angle = 0;  
  5.    while (angle < 360)  
  6.     {  
  7.         var color = Color.getColor();  
  8.        (function (t, c)  
  9.          {  
  10.              r.circle(320, 450, 20).attr({ stroke: c, fill: c, transform: t, "fill-opacity": .4 }).click(function () {  
  11.              s.animate({ transform: t, stroke: c }, 2000, "bounce");  
  12.         }).mouseover(function ()  
  13.            {  
  14.             this.animate({ "fill-opacity": .75 }, 500);  
  15.         }).mouseout(function ()  
  16.             {  
  17.             this.animate({ "fill-opacity": .4 }, 500);  
  18.         });  
  19.     })("r" + angle + " 320 240", color);  
  20.     angle += 30;  
  21. }  
  22. Color.getColor.reset();  
  23. var s = r.set();  
  24. s.push(r.path("M320,240c-50,100,50,110,0,190").attr({ fill: "none", "stroke-width": 2 }));  
  25. s.push(r.circle(320, 450, 20).attr({ fill: "none", "stroke-width": 2 }));  
  26. s.push(r.circle(320, 240, 5).attr({ fill: "none", "stroke-width": 10 }));  
  27. s.attr({ stroke: Color.getColor() });  
  28. };  
Step 4: In this section, we are going to become familiar with the body part of HTML scripting. Replace this script from the body section of the roundaboutpointer.aspx page. Here we pass a #holder in the div id that is defined in the d1.css file.
  1. <body>   
  2.        <div id="holder"></div>  
  3. </body>  
Step 5: The Complete code for Playground application.
  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="roundaboutpointer.aspx.cs" Inherits="_Default" %>   
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">   
  4. <head runat="server">   
  5.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   
  6.         <title></title>   
  7.         <link rel="stylesheet" href="d1.css" type="text/css" media="screen">   
  8.         <link rel="stylesheet" href="d2.css" type="text/css" media="print">   
  9.         <script src="js1.js" type="text/javascript" charset="utf-8"></script>   
  10.         <script>   
  11.                 From Step 3 JavaScript copy from there and paste it here.   
  12.         </script>   
  13.     </head>   
  14.     <body>   
  15.         <div id="holder"></div>   
  16.     </body>   
  17. </html>  
Step 6: Output Press F5
 
Note: For the accurate output of HTML5 applications, you must have the Google Chrome browser on your PC. You can change the position by dragging the pointer to any circle as shown in the figure.
 
 
rd1.gif
  
rd2.gif
  


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles