第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么往左只回了一下,然后就開(kāi)始來(lái)回動(dòng),求大神幫忙解答

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>速度動(dòng)畫(huà)</title>
</head>
<style>

?? ?body,div,span{
?? ??? ?margin:0;
?? ??? ?padding:0;
?? ?}
?? ?#div1{
?? ??? ?width:200px;
?? ??? ?height:200px;
?? ??? ?background:red;
?? ??? ?position:relative;
?? ??? ?left:-200px;
?? ??? ?top:0;
?? ?}
?? ?#share{
?? ??? ?width:20px;
?? ??? ?height:50px;
?? ??? ?background:blue;
?? ??? ?position:absolute;
?? ??? ?left:200px;
?? ??? ?top:75px;
?? ?}
</style>

<script>
?? ?window.onload=function(){
?? ??? ?var oDiv=document.getElementById('div1');
?? ??? ?oDiv.onmouseover=function(){
?? ??? ??? ?startMove();
?? ??? ?}
?? ??? ?oDiv.onmouseout=function(){
?? ??? ??? ?startMove1();
?? ??? ?}
?? ?}
?? ?var timer=null;
?? ?
?? ?function startMove(){
?? ??? ?clearInterval(timer);//防止每次鼠標(biāo)經(jīng)過(guò)的時(shí)候都要出發(fā)定時(shí)器
?? ??? ?var oDiv=document.getElementById('div1');
?? ??? ?setInterval(function(){//定時(shí)器
?? ??? ??? ?if(oDiv.offsetLeft>=0){
?? ??? ??? ??? ?clearInterval(timer);//清空/暫停定時(shí)器
?? ??? ??? ?}else{
?? ??? ??? ??? ?oDiv.style.left=oDiv.offsetLeft+10+'px';
?? ??? ??? ?}
?? ??? ?},30)
?? ?}
?? ?
?? ?function startMove1(){
?? ??? ?clearInterval(timer);//防止每次鼠標(biāo)經(jīng)過(guò)的時(shí)候都要出發(fā)定時(shí)器
?? ??? ?var oDiv=document.getElementById('div1');
?? ??? ?setInterval(function(){//定時(shí)器
?? ??? ??? ?if(oDiv.offsetLeft<=-200){
?? ??? ??? ??? ?clearInterval(timer);//清空/暫停定時(shí)器
?? ??? ??? ?}else{
?? ??? ??? ??? ?oDiv.style.left=oDiv.offsetLeft-10+'px';
?? ??? ??? ?}
?? ??? ?},30)
?? ?}
?? ?
</script>


<body>
?? ?<div id="div1">
?? ??? ?<span id="share">分享</span>
?? ?</div>
</body>
</html>

正在回答

2 回答

你的代碼應(yīng)該修改為

<!DOCTYPE?html>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>速度動(dòng)畫(huà)</title>
</head>
<style>

????body,div,span{
????????margin:0;
????????padding:0;
????}
????#div1{
????????width:200px;
????????height:200px;
????????background:red;
????????position:relative;
????????left:-200px;
????????top:0;
????}
????#share{
????????width:20px;
????????height:50px;
????????background:blue;
????????position:absolute;
????????left:200px;
????????top:75px;
????}
</style>

<script>
????window.onload=function(){
????????var?oDiv=document.getElementById('div1');
????????oDiv.onmouseover=function(){
????????????startMove();
????????}
????????oDiv.onmouseout=function(){
????????????startMove1();
????????}
????}
????var?timer=null;
????
????function?startMove(){
????????clearInterval(timer);//防止每次鼠標(biāo)經(jīng)過(guò)的時(shí)候都要出發(fā)定時(shí)器
????????var?oDiv=document.getElementById('div1');
?????????timer=setInterval(function(){//定時(shí)器//開(kāi)啟定時(shí)器
????????????if(oDiv.offsetLeft==0){
????????????????clearInterval(timer);//清空/暫停定時(shí)器
????????????}else{
????????????????oDiv.style.left=oDiv.offsetLeft+10+'px';
????????????}
????????},30)
????}
????
????function?startMove1(){
????????clearInterval(timer);//防止每次鼠標(biāo)經(jīng)過(guò)的時(shí)候都要出發(fā)定時(shí)器
????????var?oDiv=document.getElementById('div1');
????????timer=setInterval(function(){//定時(shí)器
????????????if(oDiv.offsetLeft==-200){
????????????????clearInterval(timer);//清空/暫停定時(shí)器
????????????}else{
????????????????oDiv.style.left=oDiv.offsetLeft-10+'px';
????????????}
????????},30)
????}
????
</script>


<body>
????<div?id="div1">
????????<span?id="share">分享</span>
????</div>
</body>
</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

y年華游你 提問(wèn)者

非常感謝!
2016-03-03 回復(fù) 有任何疑惑可以回復(fù)我~

你這個(gè)錯(cuò)誤很低級(jí),你要清除定時(shí)器,可你的timer是啟動(dòng)的定時(shí)器嗎?你需要將啟動(dòng)定時(shí)給timer才能清除。timer=setInterval();然后clearInterval(timer);

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JS動(dòng)畫(huà)效果
  • 參與學(xué)習(xí)       113920    人
  • 解答問(wèn)題       1487    個(gè)

通過(guò)本課程JS動(dòng)畫(huà)的學(xué)習(xí),從簡(jiǎn)單動(dòng)畫(huà)開(kāi)始,逐步深入各種動(dòng)畫(huà)框架封裝

進(jìn)入課程

為什么往左只回了一下,然后就開(kāi)始來(lái)回動(dòng),求大神幫忙解答

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)