<script type="text/javascript">
//***************************Class _geekees.Animator********************************
//initialize
if (typeof(_geekees.Animator) == "undefined")
_geekees.Animator = {};
else
alert("Animator is already set!");
//constructor
_geekees.Animator = function( containerId
, width
, height
, initialPosX
, initialPosY
, motionTime
, stepX
, stepY ){
this.container = $( containerId );
this.container.style.width = width + "px";
this.container.style.height = height + "px";
this.container.style.backgroundPosition = initialPosX + "px " + initialPosY + "px";
this.startPosX = 0;
this.startPosY = 0;
this.endPosX = 0;
this.endPosY = 0;
this.isForwardX = true;
this.isForwardY = true;
this.motionTime = motionTime;
this.timer = new Timer( this );//initial the Timer class
this.stepX = stepX;//each time moving step
this.stepY = stepY;
}
//move method
_geekees.Animator.prototype.move = function(){
if (this.isForwardX) {
if (this.startPosX < this.endPosX) {
this.timer.setTimeout('move', this.motionTime);
this.startPosX += this.stepX;
}
}
else {
if (this.startPosX > this.endPosX) {
this.timer.setTimeout('move', this.motionTime);
this.startPosX -= this.stepX;
}
}
if (this.isForwardY) {
if (this.startPosY < this.endPosY) {
this.timer.setTimeout('move', this.motionTime);
this.startPosY += this.stepY;
}
}
else {
if (this.startPosY > this.endPosY) {
this.timer.setTimeout('move', this.motionTime);
this.startPosY -= this.stepY;
}
}
//set the container status
this.container.style.backgroundPosition = this.startPosX + "px " + this.startPosY + "px";
}
//the method which to be called
_geekees.Animator.prototype.animate = function( startX, endX, startY, endY ){
this.startPosX = startX;
this.endPosX = endX;
this.startPosY = startY;
this.endPosY = endY;
this.isForwardX = startX <= endX;//determine whether start position is larger than end position
this.isForwardY = startY <= endY;
this.move();
}
//***************************End of Class _geekees.Animator********************************
/**//******************test*******************/
function go(){
ani.animate( 0, -208, 0, 0 );
}
function back(){
ani.animate( -208, 0, 0, 0 );
}
var ani = new _geekees.Animator( 'divAni', 52, 37, 0, 0, 100 ,52, 0);
</script>