<script type="text/javascript">
window.onload=function()
{
var oDiv=document.getElementById('div1');
//鼠标移入
oDiv.onmouseover=function(){
startmove(0);
}
//鼠标移出
oDiv.onmouseout=function(){
startmove(-200);
}
}
var timer=null;
function startmove(target){
clearInterval(timer);
var oDiv=document.getElementById('div1');
timer=setInterval(function(){
var speed=(target-oDiv.offsetLeft)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(oDiv.offsetLeft==target){
clearInterval(timer);
}
else
{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30);
}
</script>
MarlboroKay
相关分类