I am simply trying to create a class that moves a specified DIV when the mouse is on the DIV. My problem seems to be because I am specifying a method of my custom class as the event handler. My question is can I specify the method of an object as an event Handler? Or is there any other way to do this?
<script type="text/javascript">
<!--
function MovingDIV()
{
this.DIV;
this.posX;
this.intervalID;
this.StartDIV = StartDIV;
this.MoveDIV = MoveDIV;
this.StopDIV = StopDIV;
}
function MovingDIV(DIVname)
{
this.DIV = document.getElementById(DIVname);
}
function StartDIV()
{
this.intervalID = setInterval(this.MoveDIV, 100);
}
function MoveDIV()
{
this.posX = parseInt(this.DIV.style.left);
this.posX += offset;
this.DIV.style.left = this.posX;
if(this.posX > 500)
{
offset = -50;
}
else if(this.posX < 50)
{
offset = 50;
}
}
function StopDIV()
{
clearInterval(this.intervalID);
}
var MyMovingDIV = new MovingDIV("moving_div");
var test = 123;
//-->
</script>
<div id="moving_div" style="border: 5px outset blue; width: 160px; background-color: yellow; color: red; position: absolute; left: 400;" onmouseover = "MyMovingDIV.StartDIV()" onmouseout = "MyMovingDIV.StopDIV()">
THE MOVING DIV CLASS
</div>