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

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

為什么我的回去之后越動越亂

<!DOCTYPE HTML>
<html>
<head>
? <meta charset="UTF-8">
<style type="text/css">
?*{margin: 0;padding: 0}
?? ?#red{
?? ??? ? width:100px;height: 100px;background: red;position:relative;left: -100px;

?? ??? ?}
?? ?#blue{
? ?? ??? ?width: 20px;height: 40px;background-color: blue;position: absolute;left: 100px;margin-top:30px;font-size: 10px;
?? ??? ?}
</style>
<script type="text/javascript">
? window.onload=function(){
? ?? ?? var red=document.getElementById('red');
? ?? ??? ?var blue=document.getElementById('blue');
? ?? ??? ?red.onmouseover=function(){
? ?? ??? ??? ?startMove(10,0);
? ?? ??? ?}
? ?? ??? ?red.onmouseout=function(){
? ?? ??? ??? ?startMove(-10,-100);
? ?? ??? ?}
? }
???? var timer=null;

? ??? ?function startMove(speed,itarget){
? ??? ??? ?//? ??? ?function startMove(itarget){

? ??? ??? ?clearInterval(timer);
? ??? ??? ?var red=document.getElementById('red');
? ??? ??? ?var timer=setInterval(function(){
? ??? ??? ??? ?//單參數(shù)方法
? ??? ??? ??? ?/*var speed=0;
? ??? ??? ??? ?if(red.offsetLeft>itarget){
? ??? ??? ? ?? ?speed=-1;
? ??? ??? ??? ?}else{
? ??? ??? ??? ? speed=1;
? ??? ??? ??? ?}*/
? ??? ??? ?if(red.offsetLeft==itarget){
? ??? ??? ??? ??? ?clearInterval(timer);
? ??? ??? ??? ?}
? ??? ??? ?else{
? ??? ??? ??? ?red.style.left=red.offsetLeft+speed+'px';}
? ??? ??? ?},30)
? ??? ?}
</script>
?? ?<title>移動效果</title>
</head>
<body>
?? ?<div id="red"><div id="blue"></div></div>
?? ?
</body>
</html>

正在回答

1 回答

? ? ?var timer=null;

? ??? ?function startMove(speed,itarget){
? ??? ??? ?//? ??? ?function startMove(itarget){

? ??? ??? ?clearInterval(timer);
? ??? ??? ?var red=document.getElementById('red');
? ??? ??? ?var timer=setInterval(function(){
? ??? ??? ??? ?//單參數(shù)方法
? ??? ??? ??? ?/*var speed=0;


startMove里面的timer前面不能加var聲明 加的話你前面清除的是方面外面的全局timer 然后你每次執(zhí)行方法都重新定義了一個局部的timer定時器 ?簡單說方面里面定時器的timer不是外面全局的timer

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

風(fēng)谷菌 提問者

謝謝 看了半天orz
2016-03-23 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么我的回去之后越動越亂

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

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

幫助反饋 APP下載

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

公眾號

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