<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body,div,span{
margin: 0;
padding: 0;
}
#div1{
width: 200px;
height: 200px;
background: red;
position: relative;
left: -200px;
top: 0;
}
#div1 span {
width: 20px;
height: 50px;
background: blue;
position: absolute;
left: 200px;
top: 75px;
}
</style>
<script>
var timer=null;
function smove(taget){
clearInterval(timer);
var ddd=document.getElementById('div1');
timer=setInterval(function(){
if(ddd.offsetLeft>taget)
var speed=-10;
else
var speed=10;
if(ddd.offsetLeft==taget)
clearInterval(timer)
else{ddd.style.left=ddd.offsetLeft+speed+'px'}},30)
}
</script>
</head>
<body>
<div id='div1'>
<span>分享</span> <!-- 点分享时div1有效,事件冒泡 -->
</div>
</body>
<script>
window.onload=function(){
var ddd=document.getElementById('div1');
ddd.onmouseover=function(){
smove(0);
}
ddd.onmouseout=function(){
smove(-200);
}
}
</script>
</html>
西兰花伟大炮
我爱吃牛排