<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxx</title>
<style type="text/css">
body{
margin:0;padding: 0;
}
#dds{
width: 400px;
height: 400px;
position: relative;
background-color: yellow;
left: -400px;
}
#dd{
background-color: blue;
height: 50px;
width: 50px;
position: absolute;
left: 400px;
top: 175px;
}
</style>
<script type="text/javascript">
window.onload=function () {
var odiv=document.getElementById('dds');
odiv.ommouseover = function(){
startMove(400);
}
odiv.ommouseout = function(){
startMove(0);
}
}
var timer = null;
function startMove(itarget){
clearInterval(timer);
var odiv = document.getElementById('dds');
timer = setInterval(function(){
var speed=0;
if (odiv.offsetLeft>itarget) {
speed=-10;
}
else{
speed=10;
}
if (odiv.offsetLeft==itarget) {
clearInterval(timer);
}
else{
odiv.style.left=odiv.offsetLeft+speed+'px';
}
},30)
}
</script>
</head>
<body>
<div id='dds'>
<span id='dd'>分享</span>
</div>
</body>
</html>