亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么當我移動到left:200px的時候移出效果無效了

<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>運動動畫效果</title>
<style>
*{margin:0px;padding:?0px;font-size:?14px;clear:?both;}
#div1{
width:?200px;
height:?200px;
background-color:?red;
opacity:?0.3;
filter:alpha(opacity:30);
left:?-200px;
position:?relative;
top:?0px;
}
#share{
width:?20px;
height:?50px;
background-color:?blue;
/*font-size:?24px;*/
/*font-weight:?bold;*/
font-family:?'微軟雅黑';
/*float:?left;*/
position:?absolute;
left:?200px;
text-align:?center;
top:?75px;
}
</style>
<script>
window.onload?=?function(){
//?getdiv();
var?oDiv?=?document.getElementById('div1');
oDiv.onmouseover?=?function(){
startMove(0);
}
oDiv.onmouseout?=?function(){
startMove(-200);
}
}
function?getdiv(){
var?oDiv?=?document.getElementById('div1');
//?var?share?=?document.getElementById('share');
}
var?timer?=?null;
function?startMove(itarget){
var?oDiv?=?document.getElementById('div1');
//?getdiv();
clearInterval(timer);
timer?=?setInterval(function(){
var?speed?=?0;
if(oDiv.offsetLeft?>?itarget){
speed?=?-10;
}else?if(oDiv.offsetLeft?<?itarget){
speed?=?10;
}else{
speed?=?0;
}
if(oDiv.offsetLeft?==?0){
clearInterval(timer);
}else{
oDiv.style.left?=?oDiv.offsetLeft?+?speed?+'px';
}
},?30);
}
</script>
</head>
<body>
<div?id="div1"><span?id='share'>分享</span></div>
</body>
</html>
//以上是我的代碼,當我的left=0px的時候,我的onmoueout效果就無效了,鼠標移出并不能回去了,請問怎么回事呢


正在回答

1 回答

function?startMove(itarget){
????????????var?oDiv?=?document.getElementById('div1');
//?getdiv();
????????????clearInterval(timer);
????????????timer?=?setInterval(function(){
????????????????var?speed?=?0;
????????????????if(oDiv.offsetLeft?>?itarget){
????????????????????speed?=?-10;
????????????????}else?if(oDiv.offsetLeft?<?itarget){
????????????????????speed?=?10;
????????????????}else{
????????????????????speed?=?0;
????????????????????clearInterval(timer);
????????????????}
????????????????oDiv.style.left?=?oDiv.offsetLeft?+?speed?+'px';
????????????},?30);
????????}


0 回復 有任何疑惑可以回復我~
#1

carolcoral 提問者

請問什么地方修改了?
2015-12-02 回復 有任何疑惑可以回復我~
#2

carolcoral 提問者

為什么不加這個判斷了呢 if(oDiv.offsetLeft == 0){ clearInterval(timer); }else{
2015-12-02 回復 有任何疑惑可以回復我~
#3

carolcoral 提問者

非常感謝!解決了,應該就是判斷為0
2015-12-02 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么當我移動到left:200px的時候移出效果無效了

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號