大家?guī)臀铱聪聻槭裁词髽?biāo)移出沒(méi)反應(yīng)(不會(huì)縮回去),謝謝
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JS動(dòng)畫2</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 type="text/javascript">
? window.onload=function(){
? ? var ?oDiv=document.getElementById('div1');
? ? oDiv.onmouseover=function(){
? ? ? startMove();
? ? }
? ? ODiv.onmouseout=function(){
? ? ? startMove1(); ? ? ?
? ? }
? }
? //定義定時(shí)器初始化為null
? var timer=null;
? function startMove(){
? ? ? //先清除之前的定時(shí)器 ? ?
? ? clearInterval(timer);
? ? var ?oDiv=document.getElementById('div1'); ??
? ? timer=setInterval(function(){
? ? if(oDiv.offsetLeft==0){
? ? ? clearInterval(timer);
? ? }
? ? else{
? ? oDiv.style.left=oDiv.offsetLeft+10+'px';
? ? }
? ? },30)
? }
//鼠標(biāo)移出
? ?function startMove1(){
? ? ? //先清除之前的定時(shí)器 ? ?
? ? clearInterval(timer);
? ? var ?oDiv=document.getElementById('div1');
? ? timer=setInterval(function(){
? ? if(oDiv.offsetLeft==-200){
? ? ? clearInterval(timer);
? ? }
? ? else{
? ? oDiv.style.left=oDiv.offsetLeft-10+'px';
? ? }
? ? },30)
? }?
?//30表示:每隔30毫秒,就執(zhí)行一次function里面的操作
</script>
</head>
<body>
<div id="div1"><span id="share">分享</span></div>
</body>
</html>
2019-02-19
你這個(gè)是大寫,我的出毛病是……startMove? 寫成? ?strtMove……哎
2019-02-09
萌新路過(guò)
2019-01-15
有一個(gè)大寫有問(wèn)題