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

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

能否不使用object.offsetLeft

	<script>
	window.onload=function(){
		var?movepart=document.getElementById("movepart");
		movepart.onmouseover=function(){
			rightmove(0);
		}
		movepart.onmouseout=function(){
			rightmove(-1000);
		}
	}
	var?funa=null;
	function?rightmove?(target)?{
		clearInterval(funa);
		var?movepart=document.getElementById("movepart");
		funa=setInterval(function(){
			var?speed=0;
			if?(movepart.offsetLeft?<?target)?{
				speed=10;
			}
			if?(movepart.offsetLeft?>?target)?{
				speed=-10;
			}
			if?(movepart.offsetLeft?==?target)?{
				clearInterval(funa);
			}?else{
				movepart.style.left=movepart.offsetLeft+speed+'px';
			}
		},1)
	}
	</script>

之前好像在哪里看到只使用object.style.left,就可以控制的動畫的,如何實現?

正在回答

3 回答

首先你的object是什么? ? ?如果和你上面的movepart一樣,是一個dom節點,那就和你代碼是一樣的。沒什么區別呀。

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

YoungforU 提問者

movepart.style.left的值是200px,有單位,不能拿來和數字比較。如果不用offsetLeft有沒有方法解決? 然后想著定義一個變量length,來存放left的值(初始是-1000)。但是代碼有問題,能幫忙看下嗎?如下:
2015-11-16 回復 有任何疑惑可以回復我~
?funa=setInterval(function(){
	????????if?(length?<?target)?{
	????????????length=length+10;
	????????????movepart.style.left=length+'px';
	????????}
	????????if?(length?>?target)?{
	????????????length=length-10;
	????????????movepart.style.left=length+'px';
	????????}
	????????if?(length?==?target)?{
	????????????clearInterval(funa);
	????????}
	????},1)


找到問題了,謝謝??!

0 回復 有任何疑惑可以回復我~
	<script>
	window.onload=function(){
	????var?movepart=document.getElementById("movepart");
	????movepart.onmouseover=function(){
	????????rightmove(0);
	????}
	????movepart.onmouseout=function(){
	????????rightmove(-1000);
	????}
	}
	var?funa=null;
	var?length=-1000;
	function?rightmove(target){
	????clearInterval(funa);
	????var?movepart=document.getElementById("movepart");
	????funa=setInterval(function(){
	????????if?(length?<?target)?{
	????????????movepart.style.left=length+10+'px';
	????????}
	????????if?(length?>?target)?{
	????????????movepart.style.left=length-10+'px';
	????????}
	????????if?(length?==?target)?{
	????????????clearInterval(funa);
	????????}
	????},1)
	}
	</script>


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

舉報

0/150
提交
取消

能否不使用object.offsetLeft

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

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

幫助反饋 APP下載

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

公眾號

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