<html> <head>
<style type="text/css">
#all{
position:absolute;
left:0px;
top:0px;
width:100%;
height:auto;
}
#main{
position:relative;
top:30px;
border-width:1px;
border-color:red;
border-style:dashed;
}
#inner{
position:absolute;
}
</style>
<script type="text/javascript">
var step=10;
var interval=200;
var direction=true;
var flag=true;
function changeStatus(){
if(flag){
flag=false;
document.getElementById('control').style.color="green";
document.getElementById('control').value="Continue";
}else{
flag=true;
document.getElementById('control').style.color="red";
document.getElementById('control').value="Stop";
move();
}
}
function move(){
if(flag){
innerleft=parseInt(document.getElementById('inner').style.left);
innerwidth=parseInt(document.getElementById('inner').style.width);
mainwidth=parseInt(document.getElementById('main').style.width);
if(direction){
if(innerleft+innerwidth+step<=mainwidth){
document.getElementById('inner').style.left=(innerleft+step).toString()+"px";
}else{
direction=false;
document.getElementById('inner').src="picture/left.gif";
}
}else{
if(innerleft-step>=0){
document.getElementById('inner').style.left=(innerleft-step).toString()+"px";
}else{
direction=true;
document.getElementById('inner').src="picture/right.gif";
}
}
setTimeout('move()',interval);
}
}
</script>
</head>
<body>
<div id="all" align="center">
<div id="main" style="width:500px;height:500px">
<img id="inner" src="picture/right.gif" style="left:0px;top:0px;width:20px;height:20px"/>
</div>
<div style="margin-top:60px">
<input id="control" type="button" value="Stop" style="color:red" onclick="javascript:changeStatus();">
</div>
</div>
<script type="text/javascript">move();</script>
</body>
</html>