<!DOCTYPE html><html><head>? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />? ? <title>動(dòng)畫</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></head><script>? ?window.onload=function(){? ? ? ?var Odiv=document.getElementById('div1');? ? ? ?Odiv.onmouseover=function(){? ? ? ? ? ?startmove();? ? ? ?}? ?}? ?var timer=null;? ? function startmove(){? ? ? ? var Odiv=document.getElementById('div1');timer=setInterval(function(){? ? ? ? ? ? if(Odiv.offsetLeft==0){? ? ? ? ? ? ? ? clearInterval(timer);? ? ? ? ? ? }? ? else{? ? ? ? Odiv.style.left=Odiv.offsetLeft+10+'px';}? ? ? ? },30)? ? }? ? </script><body><div id="div1"><span id="share">分享</span></div></body></html>
3 回答

lijune
TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超0個(gè)贊
span是塊狀元素,你把它變成relative就相當(dāng)于浮動(dòng)了變成了內(nèi)聯(lián)元素
添加回答
舉報(bào)
0/150
提交
取消