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

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

求大神來(lái)幫我解釋一下這段代碼!??!

var?_al?=?[];
function?waterfall(){
?????//?計(jì)算及定位數(shù)據(jù)塊顯示分散效果
?????var?_pin?=?$("#main").find(".pin");
?????var?_pw?=?_pin.eq(0).outerWidth();
?????var?_wh?=?$(window).height()/2;
?????var?_ww?=?$(window).width();
????????
????var?_co?=?Math.floor(_ww/_pw);
????var?_pi?=?_pin.length;
????//?初始化數(shù)組
????for(var?i?in?_pin){
????????if(i<_co){
????????????_al.push(0);
????????}
????????_pin.eq(i).css({
????????????top:_wh,
????????????left:'50%',
????????????'margin-top':-(_pin.height()/2)+((Math.floor(Math.random()*10)<5?-1:1)*Math.floor(Math.random()*200)),
????????????'margin-left':-(_pin.width()/2)+((Math.floor(Math.random()*10)<5?-1:1)*Math.floor(Math.random()*200))
????????});
????}
????animateWater(_pin,0,_pw);
}
function?animateWater(_pin,_i,_pw){
????????var?_t?=?getMin(_al);
????????_pin.eq(_i).animate({
????????????left:_t*_pw,
????????????'margin':0,
????????????top:_al[_t]
????????},300,function(){
????????????_al[_t]+=_pin.eq(_i).outerHeight();
????????????_i++;
????????????animateWater(_pin,_i,_pw);
????????})
}

function?getMin(_al){
????var?_minT?=?Math.min.apply(null,_al);
????for(var?i?in?_al){
????????if(_al[i]==_minT){
????????????return?i;
????????}
????}
}
  1. 'margin-top':-(_pin.height()/2)+((Math.floor(Math.random()*10)<5?-1:1)*Math.floor(Math.random()*200)),
    ?'margin-left':-(_pin.width()/2)+((Math.floor(Math.random()*10)<5?-1:1)*Math.floor(Math.random()*200))

    對(duì)于這兩行十分不解,

  2. animateWater()會(huì)不會(huì)無(wú)限循環(huán),為什么?


正在回答

2 回答

棒棒的

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

試答我的理解,純當(dāng)交流:

  1. 分別生成隨機(jī)的margin-top和margin-left值,通過(guò)Math.random()方法組合生成隨機(jī)數(shù)值,如:

    Math.random()*10)<5?-1:1--->生成10以內(nèi)的隨機(jī)數(shù),如小于5,則返回-1;如大于5,則返回1;

    Math.random()*200--->生成200以內(nèi)的隨機(jī)數(shù)

    結(jié)合起來(lái)((Math.floor(Math.random()*10)<5?-1:1)*Math.floor(Math.random()*200)),就是生成正負(fù)200以內(nèi)的隨機(jī)數(shù),其他的數(shù)值,前邊代碼都固定值了,對(duì)應(yīng)加上就是。

  2. 不會(huì)無(wú)限循環(huán),驗(yàn)證過(guò)了,至于為什么,我的理解是:

    _pin.eq(_i).animate()其中.eq(_i)傳入的_i最終會(huì)超出_pin對(duì)象的索引范圍,此時(shí)應(yīng)該是構(gòu)造了一個(gè)空對(duì)象,空對(duì)象不能執(zhí)行.animate()方法吧(PS:個(gè)人理解,還待驗(yàn)證)

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

舉報(bào)

0/150
提交
取消

求大神來(lái)幫我解釋一下這段代碼!??!

我要回答 關(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)