<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>relative样式</title>
<style type="text/css">
*{margin:0;padding:0;}
#div1{
width:200px;
height:200px;
background:red;
position:relative;
left:-100px;
top:0px;
}
#share{
width:50px;
height:100px;
background:blue;
position:absolute;
left:200px;
top:50px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div1")
oDiv.onmouseover=function(){
startMove()
}
}
function startMove(){
var oDiv=document.getElementById("div1")
setInterval(function(){
oDiv.style.left=oDiv.offsetLeft+10+'px'
} 30)
}
</script>
</head>
<body>
<div id="div1"><span id="share">move</span></div>
</body>
</html>
相关分类