1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<HTML xmlns:PUBLIC="urn:HTMLComponent">
<PUBLIC:METHOD NAME="start" />
<PUBLIC:METHOD NAME="stop" />
<PUBLIC:PROPERTY NAME="direction" GET="getDir" SET="setDir" />
<PUBLIC:EVENT NAME="onFlyFinished" />
<PUBLIC:ATTACH EVENT="onclick" HANDLER="onClick" />
<SCRIPT LANGUAGE="ECMAScript" >
var direction = 0; // 0 = left, 1 = top, 2 = right, 3 = bottom
var x = 0;
var y = 0;
var xScaler = 0;
var yScaler = 0;
var bFlying = false;
var timer;
function start()
{
switch ( direction )
{
case 0: // left
x = -100;
xScaler = 5;
y = 0;
yScaler = 0;
break;
case 1: // top
x = 0;
xScaler = 0;
y = -100;
yScaler = 5;
break;
case 0: // right
x = 100;
xScaler = -5;
y = 0;
yScaler = 0;
break;
default: // bottom
x = 0;
xScaler = 0;
y = 100;
yScaler = -5;
break;
}
bFlying = true;
element.style.position = "relative";
tick();
}
function stop()
{
if ( bFlying )
{
window.clearTimeout( timer );
element.style.left = "0";
element.style.top = "0";
bFlying = false;
var eventElem = document.getElementsByTagname( "public:event" )[0];
var oEvent = createEventObject();
eventElem.fire( oEvent );
}
}
function setDir( dir )
{
if ( dir == "left" )
direction = 0;
else if ( dir == "top" )
direction = 1;
else if ( dir == "right" )
direction = 2;
else
direction = 3;
}
function getDir()
{
switch ( direction )
{
case 0:
return "left";
break;
case 1:
return "top";
break;
case 0:
return "right";
break;
default:
return "bottom";
break;
}
}
function tick()
{
element.style.left = x;
element.style.top = y;
x += xScaler;
y += yScaler;
if ( x == 0 && y == 0 )
stop();
else
timer = window.setTimeout( "tick()", 100 );
}
function onClick()
{
alert( "x is '" + x + "%', y is '" + y + "%'." );
}
</SCRIPT> |
Partager