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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

javascript瀑布流圖片定位問題

javascript瀑布流圖片定位問題

趙日天l 2016-07-27 14:11:24
for(var i = 0; i < aBox.length; i++) {? ? ? ? if(i < cnum) {? ? ? ? ? ? aBox[i].style.top = 0 + 'px';? ? ? ? ? ? aBox[i].style.left = boxwidth * i + 'px';? ? ? ? ? ? aBoxHeight.push(aBox[i].offsetHeight);? ? ? ? }? ? ? ? else {? ? ? ? ? ? var minHeight = Math.min.apply(null,aBoxHeight);? ? ? ? ? ? var minIndex = getIndex(aBoxHeight,minHeight);? ? ? ? ? ? aBox[i].style.position = 'absolute';? ? ? ? ? ? aBox[i].style.top = minHeight+'px';? ? ? ? ? ? aBox[i].style.left = aBox[minIndex].offsetLeft+'px';? ? ? ? ? ? aBoxHeight[minIndex] +=aBox[i].offsetHeight;?? ? ? ? }? ? }??aBox[i].style.top = 0 + 'px';前面為什么不加上一句?aBox[i].style.position = 'absolute';第一行以外的圖片定位都加了的
查看完整描述

1 回答

?
回夢

TA貢獻18條經驗 獲得超5個贊

position:absolute是絕對定位,進行絕對定位之后元素脫離文本流,以父輩往上擁有position:relative屬性的元素進行定位。這時候可以使用top left bottom right進行位置定位。

我雖然沒看到其余代碼,但是可以猜測

循環進行之時能跑進i < cnum這個條件里的 aBox [i]元素應該已經有了position:absolute屬性。

所以再次加上這一句等于重復操作。當然加上也不會產生錯誤,只不過做了無用功。

你可以自己打個斷點看看是否是這樣。

查看完整回答
反對 回復 2016-07-28
  • 1 回答
  • 0 關注
  • 1196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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