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

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

求助,為什鼠標必須在藍色部分才向前運動啊???鼠標移入不應該是一次觸發,應該到鼠標移動前都執行這個動作么???代碼和老師一樣,為什么我不能像老師一樣運動?。???

<!doctype html>

<html>

<head>

? ? <meta charset="UTF-8">

? ? <title>速度動畫</title>?

<style type="text/css">

*{margin: 0;padding: 0}

#big {height: 200px;width:200px;background-color: red;position: relative;left: -200px;top: 10px}

#big span{height: 20px;width:50px;background-color: blue;position: absolute;cursor: pointer;top: 85px;left:200px;}

? ? </style>

? ?<script>

? ? var timer=null;

? ?var speed=0;

? ? ?window.onload=function(){

? ? ?var start=document.getElementById("s");

? ? ?start.onmouseover=function(){

? ? ? ? ? forth(0);

? ? ?}

? ? ?start.onmouseout=function(){

? ? ? ? back(-200);

? ? ?}

?}


? ? ?function forth(target){

? ? ? clearInterval(timer);

? ? ? var big=document.getElementById("big");

? ? ? timer=setInterval(function(){

? ? ? if(big.offsetLeft<target){

? ? ? speed=10;

? ? ? }

? ? ? ?else{

? ? ? speed=-10;

? ? ? }


? ? ? ?if(big.offsetLeft==target){

? ? ? clearInterval(timer);

? ? ? }

? ? ? else{

? ? ? ? ? ? ? ? ?big.style.left=big.offsetLeft+speed+'px';

? ? ? }

? ? ? },50)

? ? ?}


? ? ? function back(target){

? ? ? ?clearInterval(timer);

? ? ? ?var big=document.getElementById("big");

? ? ? timer=setInterval(function(){

? ? ? if(big.offsetLeft<target){

? ? ? speed=10;

? ? ? }

? ? ? else {

? ? ? speed=-10;

? ? ? }

? ? ? if(big.offsetLeft==target){

? ? ? clearInterval(timer);

? ? ? }

? ? ? else{

? ? ? ? ? ? ? ? ?big.style.left=big.offsetLeft+speed+'px';

? ? ? }

? ? ?

? ? ? },50)

? ? ?}

? ?

? ?</script>

</head>

<body>

<div id="big"><span id="s">開始</span></div>


</body>

</html>


鼠標移入藍色部分物體開始運動,但是當藍色部分將要離開鼠標的時候(鼠標不動,物體向前運動)就不向前了,就開始向前向后患者來????

https://img1.sycdn.imooc.com//5c792b7c0001f1fc01310222.jpg

正在回答

1 回答

你的鼠標移入移出事件是綁定在藍色部分的,而藍色部分是包含在div里的;你換成綁定在big上 就好了

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

舉報

0/150
提交
取消

求助,為什鼠標必須在藍色部分才向前運動?????鼠標移入不應該是一次觸發,應該到鼠標移動前都執行這個動作么???代碼和老師一樣,為什么我不能像老師一樣運動?????

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

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

幫助反饋 APP下載

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

公眾號

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