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

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

關(guān)于完美運(yùn)動(dòng)框架小bug的修復(fù),附源碼

自己寫(xiě)了一遍完美框架,發(fā)現(xiàn)很多重要的小細(xì)節(jié)(主要還是變量聲明的位置問(wèn)題,即什么時(shí)候聲明)。然后,看了樓下 @赫克托耳 同學(xué)的評(píng)論,說(shuō)一下關(guān)于他提出的問(wèn)題3:【無(wú)法執(zhí)行回調(diào)函數(shù)的解決方法 】

1、我先用控制臺(tái)在每次for-in循環(huán)的結(jié)尾輸出了flag的值。發(fā)現(xiàn),flag變?yōu)閒alse后,沒(méi)有使其變成true的觸發(fā)語(yǔ)句?。ú恢览蠋煘槭裁茨軋?zhí)行,疑問(wèn))

2、也想過(guò) @赫克托耳 同學(xué)提到的 if(json[attr] != curStyle){flag= false;}else{flag=true;} 這種。但這種肯定不對(duì)?

3、于是想到在每次時(shí)間間隔開(kāi)始置flag為true,

???? 回調(diào)函數(shù)這一問(wèn)題的解決方法,就是下面代碼的第6行。

????源碼給大家了,大家最好自己敲一遍哦,反正我自己在敲得時(shí)候有太多問(wèn)題了。

//?完美運(yùn)動(dòng)框架
function?startMove(obj,json,fn){
	var?flag?=?true;
	clearInterval(obj.timer);
	obj.timer?=?setInterval(function(){
			flag?=?true;//????親們,就是這一句啊,重要的一句啊
			var?speed?=?0,
				icur?=?null;
			for(var?attr?in?json)
			{
				//	判斷速度
				if(attr?==?"opacity"){
					icur?=?Math.round(parseFloat(getStyle(obj,attr))*100);
				}else{
					icur?=?parseInt(getStyle(obj,attr));
				}
				speed?=?(json[attr]?-?icur)/8;
				speed?=?speed>0?Math.ceil(speed):Math.floor(speed);
				
				//	判斷臨界值
				if(icur?!=?json[attr]){//	有一個(gè)屬性沒(méi)達(dá)到要求iT,flag就等于false
					flag?=?false;
				}
				if(attr?==?"opacity"){
					obj.style.filter?=?"alpha(opacity:"+(icur+speed)+")";
					obj.style.opacity?=?(icur+speed)/100;
				}else{
					obj.style[attr]?=?icur+speed+"px";
				}			
			}
			if(flag){//	全部屬性都達(dá)到要求iT拉
			????clearInterval(obj.timer);
			????//alert(333);
			????if(fn)fn();
			????//console.log("fn:"+fn);fn();
			}
			//console.log("flag"+flag);
		},30);
}

為自己手動(dòng)點(diǎn)贊233333,還有好像評(píng)論說(shuō)在IE下有bug,我還沒(méi)有試

正在回答

9 回答

不,這個(gè)對(duì)同時(shí)運(yùn)動(dòng)還是存在bug,flag會(huì)被修改為true,然后全部屬性并沒(méi)有到位

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

舉個(gè)栗子233 提問(wèn)者

我試試
2015-10-20 回復(fù) 有任何疑惑可以回復(fù)我~
#2

舉個(gè)栗子233 提問(wèn)者 回復(fù) 舉個(gè)栗子233 提問(wèn)者

同學(xué)能不能把你測(cè)出bug的html代碼貼出來(lái)?用文字的形式,不要圖片哦
2015-10-20 回復(fù) 有任何疑惑可以回復(fù)我~
#3

舉個(gè)栗子233 提問(wèn)者

非常感謝!同學(xué)好細(xì)心啊
2015-10-21 回復(fù) 有任何疑惑可以回復(fù)我~

還是不太懂,flag變成false后,怎么變回true,沒(méi)有這個(gè)語(yǔ)句在

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

舉個(gè)栗子233 提問(wèn)者

在setInterval定時(shí)器函數(shù)的第一句。
2016-02-10 回復(fù) 有任何疑惑可以回復(fù)我~

兄弟,我叫你聲哥


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

舉個(gè)栗子233 提問(wèn)者

不必了,女的
2015-11-15 回復(fù) 有任何疑惑可以回復(fù)我~

給一段我稍加修改的代碼:

function?motion(obj,data,fn){
	clearInterval(obj.timer);
	obj.timer?=?setInterval(function(){
		for(var?attr?in?data){
			var?attrValue?=?getStyle(obj,attr),
				sValue?=?0,
				speed?=?0,
				stop?=?0;
			if(attr=='opacity'){
				sValue?=?Math.round(parseFloat(attrValue)*100);
			}else{
				sValue?=?parseInt(attrValue);
			}
			speed?=?(data[attr]-sValue)/8;
			speed?=?speed>0?Math.ceil(speed):Math.floor(speed);
			if(sValue!=data[attr]){
				stop?=?0;
			}else{
				stop++;
			}
			if(attr=='opacity'){
				obj.style.filter?=?'alpha(opacity:'+(sValue+speed)+')';
				obj.style.opacity?=?(sValue+speed)/100;
			}else{
				obj.style[attr]?=?sValue+speed+'px';
			}
			if(stop==3){
				clearInterval(obj.timer);
				if(fn){
					fn();
				}
			}
		}
	},20);
}
function?getStyle(ele,attr){
	if(ele.currentStyle){
	//IE
		return?ele.currentStyle[attr];
	}else{
	//非IE
		return?getComputedStyle(ele,false)[attr];
	}
}


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

舉個(gè)栗子233 提問(wèn)者

如果傳進(jìn)的json對(duì)不是三個(gè)呢?
2015-10-22 回復(fù) 有任何疑惑可以回復(fù)我~
#2

joker_0042 回復(fù) 舉個(gè)栗子233 提問(wèn)者

可以增設(shè)一個(gè)空數(shù)組,將attr存儲(chǔ)進(jìn)去,最后將3改為array.length驗(yàn)證
2015-10-22 回復(fù) 有任何疑惑可以回復(fù)我~
#3

舉個(gè)栗子233 提問(wèn)者 回復(fù) joker_0042

嗯,但是調(diào)用時(shí)變麻煩不可取吧?
2015-10-22 回復(fù) 有任何疑惑可以回復(fù)我~
#4

joker_0042 回復(fù) 舉個(gè)栗子233 提問(wèn)者

嗯。開(kāi)始想的是在傳遞一個(gè)參數(shù)或者在json中添加一個(gè)存儲(chǔ)屬性個(gè)數(shù)的屬性len,但沒(méi)有這樣做。 這個(gè)框架在做最后一節(jié)中鼠標(biāo)移動(dòng)到icon圖像時(shí)圖像向上跳動(dòng)后從下方回到原位置的運(yùn)動(dòng)時(shí),透明度的設(shè)置不很精確,我想把框架中的透明度處理單獨(dú)拿出來(lái)用,效果會(huì)好些,僅作交流。
2015-10-22 回復(fù) 有任何疑惑可以回復(fù)我~
#5

jellen

if(sValue!=data[attr]){ stop = 0; }else{ stop++; } 應(yīng)該改為if(sValue==data[attr]){ stop++; }
2015-12-29 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)


?????運(yùn)動(dòng)后

562718de0001107e05000574.jpg

?


運(yùn)動(dòng)前

562718de0001bfd105000605.jpg



這樣就看出bug了吧

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

舉個(gè)栗子233 提問(wèn)者

哈哈哈,我知道你說(shuō)的bug了,是加了border之后有bug是吧? 然后我看了一下代碼,發(fā)現(xiàn)其實(shí)我早上說(shuō)的思路是對(duì)的,但是代碼確實(shí)寫(xiě)錯(cuò)了。 if(flag){ clearInterval(obj.timer);if(fn)fn();} 上面這段代碼應(yīng)該放在for-in循環(huán)外部執(zhí)行。也就是執(zhí)行一邊各個(gè)屬性都達(dá)到目標(biāo)值后flag為true。跳出for-in循環(huán)后再執(zhí)行這段代碼。
2015-10-21 回復(fù) 有任何疑惑可以回復(fù)我~
#2

舉個(gè)栗子233 提問(wèn)者

這個(gè)bug在上面的問(wèn)題中修改過(guò)來(lái)了
2015-10-21 回復(fù) 有任何疑惑可以回復(fù)我~

你想想,每次進(jìn)定時(shí)器的時(shí)候,你修改flag為true,我假設(shè)你設(shè)置的同時(shí)動(dòng)畫(huà)有著三個(gè)屬性好了

{opacity:100,width:1000,height:400}

?if(json[attr]!=current){

? ? ? ? ? ? ? ? ? ?flag=false;//在某一屬性沒(méi)到設(shè)定值時(shí),flag還是被設(shè)定為false,可是萬(wàn)一opacity先到達(dá)設(shè)定值,也就不會(huì)進(jìn)入這個(gè)修改操作,flag還是true,這是后面的清除定時(shí)器的操作依然會(huì)執(zhí)行,所以width,heigt就不會(huì)打到你預(yù)想的值,也就是不會(huì)到1000

}


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

舉個(gè)栗子233 提問(wèn)者

我測(cè)試了下沒(méi)有錯(cuò)誤呀。然后關(guān)于這個(gè)問(wèn)題,你看。 假設(shè)初值{opacity:90,width:100,height:100} 目標(biāo)值{opacity:100,width:200,height:1000}(height增加的比較多) 1、我for-in一輪,假設(shè)opacity、width、height均為到達(dá)目標(biāo)值。三個(gè)屬性均增加一個(gè)speed。此時(shí)for-in循環(huán)結(jié)束,flag為false(被置了3次false),定時(shí)器未被clearInterval。下一輪30ms,flag在定時(shí)器開(kāi)始時(shí)將被置true。
2015-10-21 回復(fù) 有任何疑惑可以回復(fù)我~
#2

舉個(gè)栗子233 提問(wèn)者

2、我再for-in一輪,假設(shè)opacity、width均到達(dá)目標(biāo)值,height未達(dá)到目標(biāo)值。開(kāi)始for-in循環(huán)了。執(zhí)行到opacity、width時(shí)【json[attr]!=current】條件不成立,flag未被置false,當(dāng)執(zhí)行到height時(shí)【json[attr]!=current】,flag被置false。定時(shí)器未被clearInterval。循環(huán)繼續(xù)。。下一輪30ms后,flag在定時(shí)器開(kāi)始時(shí)將被置true。 3、只有三者均達(dá)到目標(biāo)值。for-in循環(huán)中【json[attr]!=current】這一條件一直不成立。flag還是初始的true。此時(shí)定時(shí)器被清除。
2015-10-21 回復(fù) 有任何疑惑可以回復(fù)我~

function startMove(obj,json,FnextChange){

? ? var speed=0;

? ? var flag=true;

? ? clearInterval(obj.timer);

? ? obj.timer=setInterval(function(){

? ? ? ? ? ? for(var attr in json){

? ? ? ? ? ? ? ? flag=true;

? ? ? ? ? ? ? ? var current=0;//當(dāng)前屬性值

? ? ? ? ? ? ? ? if(attr=='opacity'){

? ? ? ? ? ? ? ? ? ? current=Math.round(parseFloat(getStyle(obj,attr))*100);

? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? current= parseInt(getStyle(obj,attr));

? ? ? ? ? ? ? ? }



? ? ? ? ? ? ? ? //計(jì)算速度

? ? ? ? ? ? ? ? speed=(json[attr]-current)/15;

? ? ? ? ? ? ? ? speed=speed<0?Math.floor(speed):Math.ceil(speed);



? ? ? ? ? ? ? ? if(json[attr]!=current){

? ? ? ? ? ? ? ? ? ?flag=false;

? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? //此種設(shè)置offsetWidth=border+padding+width,設(shè)置內(nèi)外邊距的時(shí)候會(huì)出現(xiàn)錯(cuò)誤

? ? ? ? ? ? ? ? // obj.style.width=obj.offsetWidth+speed+'px';


? ? ? ? ? ? ? ? //把屬性寫(xiě)到html元素內(nèi)聯(lián)里邊的話,可以使用obj.style.*獲取元素的屬性

? ? ? ? ? ? ? ? ? ? // obj.style.width=parseInt(obj.style.width)+speed+'px';


? ? ? ? ? ? ? ? //也可以通過(guò)api來(lái)獲取元素屬性

? ? ? ? ? ? ? ? ? ? // ie下

? ? ? ? ? ? ? ? ? ? ? ? // obj.currentStyle[attr];


? ? ? ? ? ? ? ? ? ? //火狐下

? ? ? ? ? ? ? ? ? ? ? ? // getComputedStyle(obj,false)[attr];

? ? ? ? ? ? ? ? if(attr=='opacity'){

? ? ? ? ? ? ? ? ? ? obj.style.opacity=(current+speed)/100;

? ? ? ? ? ? ? ? ? ? obj.style.filter='alpha:(opacity:'+current+speed+')';

? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? obj.style[attr]=current+speed+'px';

? ? ? ? ? ? ? ? }



? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? if(flag){

? ? ? ? ? ? ? ? ? ? // clearInterval(obj.timer);

? ? ? ? ? ? ? ? ? ? if(FnextChange){

? ? ? ? ? ? ? ? ? ? ? ? FnextChange();

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ??

? ? ? ? ? ? }

? ? ? ? ? ? ? ? // obj.style.fontSize=parseInt(getStyle(obj,'font-size'))+1+'px';

? ? ? ? },30);

? ? }

function getStyle (obj,attr) {

? ? if(obj.currentStyle){

? ? ? ? return obj.currentStyle[attr];

? ? }else{

? ? ? ? return getComputedStyle(obj,false)[attr];

? ? }

}


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

舉個(gè)栗子233 提問(wèn)者

同學(xué),是你測(cè)試發(fā)現(xiàn)了該函數(shù)在同時(shí)運(yùn)動(dòng)中會(huì)出現(xiàn)bug的【HTML】代碼啦,我想看看是什么bug,我測(cè)試了幾個(gè)案例沒(méi)有發(fā)現(xiàn)bug
2015-10-20 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//562633c400017b0414221039.jpg最后沒(méi)去定時(shí)器,效果是實(shí)現(xiàn)了,但感覺(jué)這樣不大好

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

才是正解

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

舉報(bào)

0/150
提交
取消

關(guān)于完美運(yùn)動(dòng)框架小bug的修復(fù),附源碼

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

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

幫助反饋 APP下載

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

公眾號(hào)

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