Moving a Cursor on a Dedicated Path Using HTML 5

Introduction

In this article we are going understand the concept of moving a cursor on a dedicated path using HTML 5. In this
you will see that a cursor is moving on a dedicated path while displaying in the browser.

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
cursorchangepath 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 the 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 new Web form
  • Rename it to cursorchangepath.aspx

csr.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> tags.

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

body
{
   background: #009ACD;
    color: #fff;
    font: 300 100.1% "Helvetica Neue" , Helvetica, "Arial Unicode MS" , Arial, sans-serif;
}
#holder
{
    height: 442px;
    left: 42%;
    margin: -240px 0 0 -320px;
    position: absolute;
    top: 57%;
    width: 842px;
    font-size: x-large;
    background-color: #008000;
}
#duplicate {
    bottom: 0;
    font: 300 .7em "Helvetica Neue", Helvetica, ;
    position: absolute;
    right: 1em;
    text-align: right;
}
#duplicate d {
    color: #fff;
}


d2.css scripting.

body {
    background: #fff;
    color: #000;
    font: 100.1% "Comic Sans MS", Lucida, Verdana, sans-serif;
}
#holder {
    height: 480px;
    left: 50%;
    margin: 0 0 0 -320px;
    position: absolute;
    top: 0;
    width: 640px;
}
#duplicate {
    bottom: 0;
    font-size: .7em;
    position: absolute;
    right: 1em;
    text-align: right;
}

Step 3 : In this part we need to work on some JavaScript. For fully understanding how the JavaScript works download the attached .rar file and run the cursorchangepath application.

The whole JavaScript looks as in the following.

Color("holder", 640, 480, function ()
          {
                var r = this,
                p = r.path("M295.186,122.908c12.434,18.149,32.781,18.149,45.215,0l12.152-17.736c12.434-18.149,122.908z").attr({ stroke: "#666", opacity: .3, "stroke-width": 10 }),
                over = r.path().attr({ stroke: "#fff" }),
                len = p.getTotalLength(),
                e = r.ellipse(0, 0, 7, 3).attr({ stroke: "none", fill: "#fff" }).onAnimation(function ()
                 {
                    var t = this.attr("transform");
                    over.attr({ path: "M316,248L" + t[0][1] + "," + t[0][2] + "z" });
                 });
               r.circle(316, 248, 5).attr({ stroke: "none", fill: "#fff" });
               r.customAttributes.along = function (v)
                {
                   var point = p.getPointAtLength(v * len);
                   return {
                   transform: "t" + [point.x, point.y] + "r" + point.alpha
                };
          };
            e.attr({ along: 0 });
            var rotateAlongThePath = true;
            function run()
                {
                 e.animate({ along: 1 }, 2e4, function ()
                  {
                    e.attr({ along: 0 });
                    setTimeout(run);
                });
            }
            run();
            // logo
            var logo = r.set(
            r.rect(13, 13, 116, 116, 30).attr({ stroke: "none", fill: "#fff", transform: "r45", opacity: .2 }),
            r.path("M129.657,71.361c0,3.812-1.105,7.451-3.153,10.563c-1.229,1.677-2.509,7.588c-3. 46.869").attr({ fill: "#f89938", stroke: "none", opacity: .5 }),
            r.circle(71, 32, 19).attr({ stroke: "none", fill: "#39f", opacity: .5 }));
            logo.transform("t245,177...");
            // logo end
        });


 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 cursorchangepath.aspx page. Here we pass a #holder in the div id that is defined in the d1.css file.

<body>
    <center>
        <h2>
            Changing Cursor Path on A dedicated path
        </h2>
    </center>
        <div id="holder"></div>
    </body>


Step 5 : The Complete code for the cursorchangepath application.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cursorchangepath.aspx.cs"Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="d1.css" media="screen">
    <link rel="stylesheet" href="d2.css" media="print">
    <script src="javascript.js"></script>
    <script>
    
  From Step 3 JavaScript copy from there and paste it here.
      
</script>
</head>
<
body>
    <center>
        <h2>
            Changing Cursor Path on A dedicated path
        </h2>
    </center>
        <div id="holder"></div>
    </body>
</html>

Step 6 : Output Press F5

Note :
For the accurate output of HTML5 applications, you must have the Google Chrome browser in your PC. You will see here that the cursor is moving on a dedicated path.

csr1.gif

Here you can see the cursor is moving from its position.

csr2.gif

Here are some useful resources

Animated Cursor-Custom Control
Cursors and Alternative to the Cursors in Sql server
Creating WPF window's on dedicated threads
Using Quota Template to manage site collection storage limits through Central Administration
Cursors in C#

Up Next
    Ebook Download
    View all
    Learn
    View all