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

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

JS怎么一直在抖動

<!DOCTYPE?html>
<html>
<head>
????<meta?charset="utf-8">
????<title>練習JS</title>
</head>
<style?type="text/css">
????body{
????????margin:0;
????????padding:0;
????}
????#div1{
????????width:200px;
????????height:140px;
????????background-color:?red;
????????left:?-202px;
????????position:?relative;
????}
????#div1?span{
????????width:20px;
????????height:?50px;
????????background:?#eee;
????????position:?absolute;
????????left:?200px;
????????top:75px;
????}
</style>
<body>
<div?id="div1">
????<span?id="share">分享</span>
</div>
<script>
????window.onload?=?function(){
????????var?wsc?=?document.getElementById('div1');
????????wsc.onmouseover?=?function(){
????????????startMove(0);
????????}
????????wsc.onmouseout?=?function(){
????????	starMove(-200);
????????}
????}
????var?timer?=?null;
????function?startMove(iTarget){
????	clearInterval(timer);
????????var?wsc?=?document.getElementById('div1');
????????timer?=?setInterval(function(){
????????	var?speed?=?0;
????????	if(wsc.offsetLeft?>?iTarget){
????????		speed?=?-10;
????????	}
????????		else{
????????		speed=10;
????????		}
????????	if(wsc.offsetLeft?==?iTarget){
????????		clearInterval(timer);
????????	}
????????else{
????????????wsc.style.left?=?wsc.offsetLeft?+?speed?+'px';
????????}
????????},30)
????}
</script>
</body>
</html>

JS怎么一直在抖動,完全抄老師寫的 ?可是還是一直在抖動。。。到底哪里寫錯的?

正在回答

4 回答

<!DOCTYPE?html>
<html>
<head>
????<meta?charset="utf-8">
????<title>練習JS</title>
</head>
<style?type="text/css">
????body{
????????margin:0;
????????padding:0;
????}
????#div1{
????????width:200px;
????????height:140px;
????????background-color:?red;
????????left:?-200px;
????????position:?relative;
????}
????#div1?span{
????????width:20px;
????????height:?50px;
????????background:?#eee;
????????position:?absolute;
????????left:?200px;
????????top:75px;
????}
</style>
<body>
<div?id="div1">
????<span?id="share">分享</span>
</div>
<script>
????window.onload?=?function(){
????????var?wsc?=?document.getElementById('div1');
????????wsc.onmouseover?=?function(){
????????????startMove(0);
????????}
????????wsc.onmouseout?=?function(){
????????????startMove(-200);
????????}
????}
????var?timer?=?null;
????function?startMove(iTarget){
????????clearInterval(timer);
????????var?wsc?=?document.getElementById('div1');
????????timer?=?setInterval(function(){
????????????var?speed?=?0;
????????????console.log(wsc.offsetLeft);
????????????console.log(iTarget);
????????????if(wsc.offsetLeft?>?iTarget){
????????????????speed?=?-10;
????????????}else{
????????????????console.log('出');
????????????????speed=10;
????????????????}

????????????if(wsc.offsetLeft?==?iTarget){
????????????????clearInterval(timer);
????????????}?else{
????????????wsc.style.left?=?wsc.offsetLeft?+?speed?+'px';
????????}
????????},30)
????}
</script>
</body>
</html>


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

吳思超0 提問者

非常感謝!
2015-12-10 回復 有任何疑惑可以回復我~
#2

吳思超0 提問者

你好 問下我哪里寫的不對?
2015-12-10 回復 有任何疑惑可以回復我~

應該是移動到span上div動吧,你這個寫的是移動到div上div動,而且div都已經-200,你怎么onmouseover的

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

你的div的css??left:?-202px; 改成-200 試試 我試了下可以 你再試試

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

兼容性問題

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

奶弟是林俊標

非常好
2015-12-15 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

JS怎么一直在抖動

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

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

幫助反饋 APP下載

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

公眾號

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