<script type="text/javascript">
window.onload = function(){
var i = 0;
document.getElementById('a').onclick = function(){
if(i>0) {
i = 0;
window.clearTimeout(timer);
return false;
}
(function(){
document.getElementById('span').style.left = ++i<200 ? i+'px' : i = 0;
timer = window.setTimeout(arguments.callee, 10);
})();
return false;
};
}
</script>
<style type="text/css">
a {display: block; position: relative;}
div {
border: 1px dotted #DDD;
position: absolute;
overflow: hidden;
top: 50px;
width: 500px;
height: 50px;
}
span {
background: blue;
position: absolute;
color: white;
text-align: center;
width: 50px;
height: 50px;
}
</style>
<div>
<span id="span">Text</span>
</div>
<a href="#" id="a">click</a>